+1. I thought about this case this morning after re-reading one of your
messages. I was going to look at it tonight, but this looks like the
correct fix to me.
Ryan
On Sun, 25 Aug 2002, Jim Jagielski wrote:
> Hmm. The patch doesn't seem to do the right thing if buff is non-NULL
> and len == 0 (we simple want to return the length that would be written
> but *never* actually touch buff if len == 0).
>
> The below patch should address that, but:
>
> 1. This is rushed, so I'm not sure if my assumption about
> apr_snprintf() not working right is valid
> 2. If the below will fix it.
>
> I wanted to get this out quick though...
>
> Index: strings/apr_snprintf.c
> ===================================================================
> RCS file: /home/cvs/apr/strings/apr_snprintf.c,v
> retrieving revision 1.27
> diff -u -r1.27 apr_snprintf.c
> --- strings/apr_snprintf.c 25 Aug 2002 04:22:35 -0000 1.27
> +++ strings/apr_snprintf.c 25 Aug 2002 18:19:18 -0000
> @@ -1249,9 +1249,18 @@
> 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) {
> + /* In this special case, we don't care if buff is NULL or not
> + * we just want to return the number of chars that would be written.
> + * So we leverage the fact that INS_CHAR just does the inserts
> + * iff the pointer is non-NULL */
> + 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 +1277,18 @@
> int cc;
> apr_vformatter_buff_t vbuff;
>
> - /* save one byte for nul terminator */
> - vbuff.curpos = buf;
> - vbuff.endpos = buf + len - 1;
> + if (len == 0) {
> + /* In this special case, we don't care if buff is NULL or not
> + * we just want to return the number of chars that would be written.
> + * So we leverage the fact that INS_CHAR just does the inserts
> + * iff the pointer is non-NULL */
> + 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';
>
--
_______________________________________________________________________________
Ryan Bloom [EMAIL PROTECTED]
550 Jean St
Oakland CA 94610
-------------------------------------------------------------------------------