summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2002-08-25 04:22:36 +0000
committerrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2002-08-25 04:22:36 +0000
commitc82688ea765ff684bc7d6c12ba84504f423301e7 (patch)
treedf8ee4d214f1e267d514a416da04ad918a05b17b /strings
parent933f436fc916205db7514586cf217c07545d03ad (diff)
downloadlibapr-c82688ea765ff684bc7d6c12ba84504f423301e7.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: http://svn.apache.org/repos/asf/apr/apr/trunk@63829 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings')
-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;
}