albertodemichelis / squirrel

Official repository for the programming language Squirrel
http://www.squirrel-lang.org
MIT License
913 stars 156 forks source link

Set format string for _string_printf #208

Closed atanasovdaniel closed 4 years ago

atanasovdaniel commented 4 years ago

In current implementation string "dest" is used as "format string" in call to "printfunc". This leads to unpredictable behavior if something like format string is produced by "sqstd_format". For example string "%%s" once formated results in "%s", passed to "printfunc" will try to read two integer arguments (which are not given).

Quick test: sq>printf("%%s") %s

atanasovdaniel commented 4 years ago

As current SQPRINTFUNCTION does formating there is no way to avoid multiple calls for formating.

May be it will be better if: 1) SQPRINTFUNCTION only prints a string (without formating). 2) Have a function to do formating in memory (may be in scratch pad). 3) Have a wrapper that does formating and calls SQPRINTFUNCTION.