Re: use strnlen() in vfprintf.c

2016-08-27 Thread Stefan Sperling
On Sat, Aug 27, 2016 at 07:34:53PM +0200, Ingo Schwarze wrote: > Hi Todd, > > Todd C. Miller wrote on Sat, Aug 27, 2016 at 10:28:14AM -0600: > > > Now that we have a handy size_t scratch variable, > > we can use it to store the return value of mbrtowc() > > instead of storing it in an int. Worth

Re: use strnlen() in vfprintf.c

2016-08-27 Thread Ingo Schwarze
Hi Todd, Todd C. Miller wrote on Sat, Aug 27, 2016 at 10:28:14AM -0600: > Now that we have a handy size_t scratch variable, > we can use it to store the return value of mbrtowc() > instead of storing it in an int. Worth it or overkill? Some interfaces are specifically designed to trap the unwar

Re: use strnlen() in vfprintf.c

2016-08-27 Thread Todd C. Miller
On Sat, 27 Aug 2016 12:12:02 +0200, Ingo Schwarze wrote: > However, in the case at hand, it really helps readability > in a function (unavoidably) already longer than comfortable > for reading it. Now that we have a handy size_t scratch variable, we can use it to store the return value of mbrtowc

Re: use strnlen() in vfprintf.c

2016-08-27 Thread Theo de Raadt
> in 2014, Theo scolded me when i tried to use strnlen(3) at some > place in mandoc where it wasn't really important, pointing out that > some systems still didn't have it, and saying: "Let me say simply: > Yuck." And indeed, i promptly got reports about compile failures > on Solaris. Right. > H

Re: use strnlen() in vfprintf.c

2016-08-27 Thread Ingo Schwarze
Hi Todd, in 2014, Theo scolded me when i tried to use strnlen(3) at some place in mandoc where it wasn't really important, pointing out that some systems still didn't have it, and saying: "Let me say simply: Yuck." And indeed, i promptly got reports about compile failures on Solaris. However, in

Re: use strnlen() in vfprintf.c

2016-08-25 Thread Ted Unangst
Todd C. Miller wrote: > > if (blah) { > > size_t len; > > ... > > } else { > > size_t len; > > ... > > } > > > > looks noisy to me, so I would lean towards your latter idea. > > Yeah, I just liked len being scoped that way. However, I see other > places we really want to use a si

Re: use strnlen() in vfprintf.c

2016-08-25 Thread Todd C. Miller
On Thu, 25 Aug 2016 13:56:24 -0700, Philip Guenther wrote: > This: > > if (blah) { > size_t len; > ... > } else { > size_t len; > ... > } > > looks noisy to me, so I would lean towards your latter idea. Yeah, I just liked len being scoped that way. However, I see other places w

Re: use strnlen() in vfprintf.c

2016-08-25 Thread Philip Guenther
On Thu, Aug 25, 2016 at 11:15 AM, Todd C. Miller wrote: > This is what strnlen(3) is for, let's use it... > > Alternately, we could unify things like: > > len = prec >= 0 ? strnlen(cp, prec) : strlen(cp); > if (len > INT_MAX) > goto overflow; > size = (int)l

use strnlen() in vfprintf.c

2016-08-25 Thread Todd C. Miller
This is what strnlen(3) is for, let's use it... Alternately, we could unify things like: len = prec >= 0 ? strnlen(cp, prec) : strlen(cp); if (len > INT_MAX) goto overflow; size = (int)len; but that means declaring "size_t len" at the top of the for(;;) lo