Bug #66674 [Nab]: Invalid printf() conversion code in json.c (twice)

From: Date: Sat, 08 Feb 2014 14:35:07 +0000
Subject: Bug #66674 [Nab]: Invalid printf() conversion code in json.c (twice)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184209@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66674&edit=1 ID: 66674 User updated by: tom at bignm dot com Reported by: tom at bignm dot com Summary: Invalid printf() conversion code in json.c (twice) Status: Not a bug Type: Bug Package: Compile Warning Operating System: Ubuntu Linux 11.04 PHP Version: 5.4.25 Block user comment: N Private report: N New Comment: Okay! So the spprintf() function is totally a custom function. I find it strange that the gcc compiler would apply "printf()" conversion code warning heuristics to a custom function. You may want to check out how your custom function is being declared/defined in the source and/or headers so that gcc won't apply standard C library printf() conversion code heuristics to it. Previous Comments: ------------------------------------------------------------------------ [2014-02-08 14:05:37] nikic@php.net We don't use the libc *printf functions, but have custom implementations. See for example http://lxr.php.net/xref/PHP_TRUNK/main/spprintf.c#xbuf_format_converter, which is used by (v)spprintf, and http://lxr.php.net/xref/PHP_TRUNK/main/snprintf.c#582, which is used by (v)(a)s(n|l)printf. ------------------------------------------------------------------------ [2014-02-08 13:54:57] tom at bignm dot com Okay, a custom modifier (conversion code) is wonderful. However, these need to be registered with the function 'register_printf_function()', which is nowhere to be found in the source code that I could find with grep. Unless another rarely used mechanism is in place to register this new code, it becomes pretty obvious that this is definitely a bug (intentional or not). ------------------------------------------------------------------------ [2014-02-08 12:59:22] nikic@php.net k is a custom modifier that prints a floating point number without taking locales into consideration. Is there some way to teach gcc about custom printf modifiers? ------------------------------------------------------------------------ [2014-02-08 12:18:22] tom at bignm dot com Description: ------------ When compiling PHP 5.4.25 two compilation warnings are displayed indicating an invalid printf() conversion code 'k' being used. On lines 408 and 619 inside a spprintf() calls, the following lines are found in source file 'json.c': 409: int l = spprintf(&tmp, 0, "%.*k", (int) EG(precision), d); 619: len = spprintf(&d, 0, "%.*k", (int) EG(precision), dbl); My suspicion is that the conversion code should be 'e', 'f' or 'g' instead of 'k' since the value seems to be a double being processed in both cases with a fixed precision. While only a warning, this can certainly cause invalid floating point values to be returned, possibly even causing segmentation faults in spprintf(). Test script: --------------- Not needed. Expected result: ---------------- Hopefully somebody will fix the source who knows which proper printf() conversion code to use. Actual result: -------------- Here's the 'make' line and the compiler's output for the file 'json.c': /bin/bash /usr/local/src/php-5.4.25/libtool --silent --preserve-dup-deps --mode=compile cc -Iext/json/ -I/usr/local/src/php-5.4.25/ext/json/ -DPHP_ATOM_INC -I/usr/local/src/php-5.4.25/include -I/usr/local/src/php-5.4.25/main -I/usr/local/src/php-5.4.25 -I/usr/local/src/php-5.4.25/ext/date/lib -I/usr/local/src/php-5.4.25/ext/ereg/regex -I/usr/include/libxml2 -I/usr/include/freetype2 -I/usr/local/src/php-5.4.25/ext/mbstring/oniguruma -I/usr/local/src/php-5.4.25/ext/mbstring/libmbfl -I/usr/local/src/php-5.4.25/ext/mbstring/libmbfl/mbfl -I/usr/include/mysql -I/usr/local/src/php-5.4.25/ext/sqlite3/libsqlite -I/usr/local/src/php-5.4.25/TSRM -I/usr/local/src/php-5.4.25/Zend -I/usr/include -g -O2 -fvisibility=hidden -c /usr/local/src/php-5.4.25/ext/json/json.c -o ext/json/json.lo /usr/local/src/php-5.4.25/ext/json/json.c: In function 'json_escape_string': /usr/local/src/php-5.4.25/ext/json/json.c:408:6: warning: unknown conversion type character 'k' in format /usr/local/src/php-5.4.25/ext/json/json.c: In function 'php_json_encode': /usr/local/src/php-5.4.25/ext/json/json.c:619:6: warning: unknown conversion type character 'k' in format ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66674&edit=1

« previous php.bugs (#184209) next »