summaryrefslogtreecommitdiff
path: root/strings/apr_snprintf.c
diff options
context:
space:
mode:
authorRyan Bloom <rbb@apache.org>2002-08-25 04:22:36 +0000
committerRyan Bloom <rbb@apache.org>2002-08-25 04:22:36 +0000
commit09461b774c2f10078f969d9af19a2ef8adb96f4f (patch)
treedf8ee4d214f1e267d514a416da04ad918a05b17b /strings/apr_snprintf.c
parent70bdb23bb288df73c7b97851cabcfba076141aab (diff)
downloadapr-09461b774c2f10078f969d9af19a2ef8adb96f4f.tar.gz
If the length argument to apr_snprintf is 0, then we should return the
length that the string would be if we actually were going to fill it out. However, if the length argument is 0, we can also accept a NULL string. Also, added a test case for this. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@63829 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings/apr_snprintf.c')
-rw-r--r--strings/apr_snprintf.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/strings/apr_snprintf.c b/strings/apr_snprintf.c
index a066241df..cb97e18b5 100644
--- a/strings/apr_snprintf.c
+++ b/strings/apr_snprintf.c
@@ -294,14 +294,16 @@ static char *apr_gcvt(double number, int ndigit, char *buf, boolean_e altform)
*/
#define INS_CHAR(c, sp, bep, cc) \
{ \
- if (sp >= bep) { \
- vbuff->curpos = sp; \
- if (flush_func(vbuff)) \
- return -1; \
- sp = vbuff->curpos; \
- bep = vbuff->endpos; \
+ if (sp) { \
+ if (sp >= bep) { \
+ vbuff->curpos = sp; \
+ if (flush_func(vbuff)) \
+ return -1; \
+ sp = vbuff->curpos; \
+ bep = vbuff->endpos; \
+ } \
+ *sp++ = (c); \
} \
- *sp++ = (c); \
cc++; \
}
@@ -1247,16 +1249,15 @@ APR_DECLARE_NONSTD(int) apr_snprintf(char *buf, apr_size_t len,
va_list ap;
apr_vformatter_buff_t vbuff;
- if (len == 0)
- return 0;
-
/* save one byte for nul terminator */
vbuff.curpos = buf;
vbuff.endpos = buf + len - 1;
va_start(ap, format);
cc = apr_vformatter(snprintf_flush, &vbuff, format, ap);
va_end(ap);
- *vbuff.curpos = '\0';
+ if (len != 0) {
+ *vbuff.curpos = '\0';
+ }
return (cc == -1) ? (int)len : cc;
}
@@ -1267,13 +1268,12 @@ APR_DECLARE(int) apr_vsnprintf(char *buf, apr_size_t len, const char *format,
int cc;
apr_vformatter_buff_t vbuff;
- if (len == 0)
- return 0;
-
/* save one byte for nul terminator */
vbuff.curpos = buf;
vbuff.endpos = buf + len - 1;
cc = apr_vformatter(snprintf_flush, &vbuff, format, ap);
- *vbuff.curpos = '\0';
+ if (len != 0) {
+ *vbuff.curpos = '\0';
+ }
return (cc == -1) ? (int)len : cc;
}