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

Reply via email to