Return-Path: Delivered-To: apmail-apr-cvs-archive@apr.apache.org Received: (qmail 79298 invoked by uid 500); 26 Aug 2002 17:34:08 -0000 Mailing-List: contact cvs-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: dev@apr.apache.org Delivered-To: mailing list cvs@apr.apache.org Received: (qmail 79287 invoked from network); 26 Aug 2002 17:34:07 -0000 Date: 26 Aug 2002 17:34:07 -0000 Message-ID: <20020826173407.59890.qmail@icarus.apache.org> From: jim@apache.org To: apr-cvs@apache.org Subject: cvs commit: apr/strings apr_snprintf.c X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N jim 2002/08/26 10:34:07 Modified: strings apr_snprintf.c Log: Document the len == 0 special case for apr_snprintf() and allow it to work no matter what buf is (NULL or not). Reviewed by: rbb Revision Changes Path 1.28 +24 -6 apr/strings/apr_snprintf.c Index: apr_snprintf.c =================================================================== RCS file: /home/cvs/apr/strings/apr_snprintf.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- apr_snprintf.c 25 Aug 2002 04:22:35 -0000 1.27 +++ apr_snprintf.c 26 Aug 2002 17:34:07 -0000 1.28 @@ -1249,9 +1249,21 @@ va_list ap; apr_vformatter_buff_t vbuff; - /* save one byte for nul terminator */ - vbuff.curpos = buf; - vbuff.endpos = buf + len - 1; + if (len == 0) { + /* NOTE: This is a special case; we just want to return the number + * of chars that would be written (minus \0) if the buffer + * size was infinite. We leverage the fact that INS_CHAR + * just does actual inserts iff the buffer pointer is non-NULL. + * In this case, we don't care what buf is; it can be NULL, since + * we don't touch it at all. + * / + vbuff.curpos = NULL; + vbuff.endpos = NULL; + } else { + /* 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); @@ -1268,9 +1280,15 @@ int cc; apr_vformatter_buff_t vbuff; - /* save one byte for nul terminator */ - vbuff.curpos = buf; - vbuff.endpos = buf + len - 1; + if (len == 0) { + /* See above notee */ + vbuff.curpos = NULL; + vbuff.endpos = NULL; + } else { + /* save one byte for nul terminator */ + vbuff.curpos = buf; + vbuff.endpos = buf + len - 1; + } cc = apr_vformatter(snprintf_flush, &vbuff, format, ap); if (len != 0) { *vbuff.curpos = '\0';