mirror of
https://github.com/php/php-src.git
synced 2026-04-28 10:43:30 +02:00
Fix snprintf test.
C99 allows for the Single Unix Spec semantics which prescribe a return
value of -1 for n == 0 which is treated as an encoding error.
This reenables use of snprintf on Solaris at least.
Relevant excerpts from ection 7.19.6.5:
Description
[..] If n is zero, nothing is written, and s may be a null pointer. [..]
Returns
The snprintf function returns the number of characters that would have been
written had n been sufficiently large, not counting the terminating null
character, or a negative value if an encoding error occurred.
Single Unix Spec:
http://www.opengroup.org/onlinepubs/007908799/xsh/fprintf.html
This commit is contained in:
+3
-1
@@ -1186,7 +1186,9 @@ main() {
|
||||
int res = 0;
|
||||
res = res || (snprintf(buf, 2, "marcus") != 6);
|
||||
res = res || (buf[1] != '\0');
|
||||
res = res || (snprintf(buf, 0, "boerger") != 7);
|
||||
/* Implementations may consider this as an encoding error */
|
||||
snprintf(buf, 0, "boerger");
|
||||
/* However, they MUST ignore the pointer */
|
||||
res = res || (buf[0] != 'm');
|
||||
res = res || (snprintf(NULL, 0, "boerger") != 7);
|
||||
res = res || (snprintf(buf, sizeof(buf), "%f", 0.12345678) != 8);
|
||||
|
||||
Reference in New Issue
Block a user