major formatted output function bug with %c and the value 0

marco.bodrato at tutanota.com marco.bodrato at tutanota.com
Sun Feb 18 12:29:27 CET 2024


Ciao Vincent,

15 dic 2023, 13:26 da vincent at vinc17.net:

> Note that there are similar issues in printf/repl-vsnprintf.c, and I
>

I finally had the time to examine the code and test it. I attach a proposed patch.

I changed the 3 files: printf/doprntf.c, printf/repl-vsnprintf.c, printf/sprintffuns.c, to use the returned value of the called functions, instead of calling strlen on the string.

I also slightly changed the tests, to check at least one case with "%c", 0.
For this to work I also had to change a
-  (*__gmp_free_func) (got, strlen(got)+1);
+  (*__gmp_free_func) (got, got_len+1);
When the string comes from a generic print, it is safer to relay on the return value than on the length computed by strlen()...


> think that this is the cause of the MPFR failure with MS Visual C++
> (vsnprintf is used by gmp_vasprintf).
>
If you can also test on that side, let me know. Thanks!

Gis,
m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: printf.diff
Type: text/x-patch
Size: 5384 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20240218/bfbf6551/attachment.bin>


More information about the gmp-bugs mailing list