Re: [dev] [sbase] [patch] Fix warnings about strcpy() etc. on OpenBSD

From: sin <sin_AT_2f30.org>
Date: Thu, 15 Aug 2013 14:21:57 +0300

On Thu, Aug 15, 2013 at 11:00:11AM +0000, Thorsten Glaser wrote:

> > if(len+1 > *size && !(*p = realloc(*p, len+1)))
> > eprintf("realloc:");
> >
> >- strcpy(&(*p)[len-n], buf);
> >+ snprintf(&(*p)[len-n], n+1, "%s", buf);
>
> Again, I object… you do not calculate the length correctly.
> Besides, this looks like a strlcat to me… if not, memcpy
> might again be more wise; n+1 doesn’t match with len+1 from above.

Will change these to memcpy(), thanks. However, I don't understand why n + 1
is wrong here? Consider the case when initially len = 0 and say n = 4 then we
allocate 5 bytes (to account for '\0') and len is still 4, so we start
copying to &(*p)[0] and the available space for &(*p)[0] is 5 bytes so n + 1.

> Is not using spaces around operators normal for sbase, btw?
> This is horrid. Please read https://www.mirbsd.org/man9/style
> for something nicer-looking. (I used to do it wrong, too.)

I always use spaces, however, the existing code I was changing was not
using spaces.

Thanks,
sin
Received on Thu Aug 15 2013 - 13:21:57 CEST

This archive was generated by hypermail 2.3.0 : Thu Aug 15 2013 - 13:24:06 CEST