summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2002-08-21 01:11:50 +0000
committerMarcus Boerger <helly@php.net>2002-08-21 01:11:50 +0000
commitb6cf2bb4bc68ffd4391be7ebaff4423d2c51a688 (patch)
treef6aa75fc4cd7fd02058092311e118a8c521d78ed
parentb98c26382fbce4ad781914a8e0530a0d0980b321 (diff)
downloadphp-git-b6cf2bb4bc68ffd4391be7ebaff4423d2c51a688.tar.gz
make snprintf and f,g,G converions of snprintf/spprintf C99 complient
-rw-r--r--main/snprintf.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/main/snprintf.c b/main/snprintf.c
index 6d567e536c..a8f7d75f60 100644
--- a/main/snprintf.c
+++ b/main/snprintf.c
@@ -390,8 +390,10 @@ ap_php_gcvt(double number, int ndigit, char *buf, boolean_e altform)
*p2++ = decpt % 10 + '0';
} else {
if (decpt <= 0) {
- if (*p1 != '0')
+ if (*p1 != '0') {
+ *p2++ = '0';
*p2++ = '.';
+ }
while (decpt < 0) {
decpt++;
*p2++ = '0';
@@ -444,14 +446,14 @@ typedef struct buf_area buffy;
*
* NOTE: Evaluation of the c argument should not have any side-effects
*/
-#define INS_CHAR( c, sp, bep, cc ) \
- { \
- if ( sp < bep ) \
- { \
- *sp++ = c ; \
- cc++ ; \
- } \
- }
+#define INS_CHAR(c, sp, bep, cc) \
+ { \
+ if (sp < bep) \
+ { \
+ *sp++ = c; \
+ } \
+ cc++; \
+ }
#define NUM( c ) ( c - '0' )
@@ -885,14 +887,19 @@ static void strx_printv(int *ccp, char *buf, size_t len, const char *format,
* Notice that if no length is given, we initialize buf_end to the
* highest possible address.
*/
- od.buf_end = len ? &buf[len] : (char *) ~0;
- od.nextb = buf;
+ if (len == 0) {
+ od.buf_end = (char *) ~0;
+ od.nextb = (char *) ~0;
+ } else {
+ od.buf_end = &buf[len-1];
+ od.nextb = buf;
+ }
/*
* Do the conversion
*/
cc = format_converter(&od, format, ap);
- if (len == 0 || od.nextb <= od.buf_end)
+ if (len != 0 && od.nextb <= od.buf_end)
*(od.nextb) = '\0';
if (ccp)
*ccp = cc;
@@ -905,7 +912,7 @@ int ap_php_snprintf(char *buf, size_t len, const char *format,...)
va_list ap;
va_start(ap, format);
- strx_printv(&cc, buf, (len - 1), format, ap);
+ strx_printv(&cc, buf, len, format, ap);
va_end(ap);
return (cc);
}
@@ -915,7 +922,7 @@ int ap_php_vsnprintf(char *buf, size_t len, const char *format, va_list ap)
{
int cc;
- strx_printv(&cc, buf, (len - 1), format, ap);
+ strx_printv(&cc, buf, len, format, ap);
return (cc);
}