You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jim Jagielski <ji...@jaguNET.com> on 1997/12/23 02:42:08 UTC
Re: [PATCH] ap_snprintf should be more sane (fwd)
+1
Dean Gaudet wrote:
>
> Dean
>
> Index: main/util_snprintf.c
> ===================================================================
> RCS file: /export/home/cvs/apachen/src/main/util_snprintf.c,v
> retrieving revision 1.10
> diff -u -r1.10 util_snprintf.c
> --- util_snprintf.c 1997/10/22 20:29:54 1.10
> +++ util_snprintf.c 1997/12/23 01:22:13
> @@ -903,20 +903,15 @@
> buffy od;
> int cc;
>
> - /*
> - * First initialize the descriptor
> - * Notice that if no length is given, we initialize buf_end to the
> - * highest possible address.
> - */
> - od.buf_end = len ? &buf[len] : (char *) ~0;
> + /* save 1 byte for nul terminator, we assume len > 0 */
> + 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)
> - *(od.nextb) = '\0';
> + *(od.nextb) = '\0';
> if (ccp)
> *ccp = cc;
> }
> @@ -927,8 +922,11 @@
> int cc;
> va_list ap;
>
> + if (len == 0)
> + return 0;
> +
> va_start(ap, format);
> - strx_printv(&cc, buf, (len - 1), format, ap);
> + strx_printv(&cc, buf, len, format, ap);
> va_end(ap);
> return (cc);
> }
> @@ -939,7 +937,10 @@
> {
> int cc;
>
> - strx_printv(&cc, buf, (len - 1), format, ap);
> + if (len == 0)
> + return 0;
> +
> + strx_printv(&cc, buf, len, format, ap);
> return (cc);
> }
>
>
>
--
====================================================================
Jim Jagielski | jaguNET Access Services
jim@jaguNET.com | http://www.jaguNET.com/
"Look at me! I'm wearing a cardboard belt!"