From: Ralph Corderoy Date: Sun, 1 Jul 2018 08:43:05 +0000 (+0100) Subject: mhlsbr.c: Use variable for strncpy(3)'s size, not sizeof. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/af2ad7be43057a4f82dc8a223d79d68bf932ae00?hp=fbd0002a92c15b70b8bfda4c48fff5ded89c7f04 mhlsbr.c: Use variable for strncpy(3)'s size, not sizeof. Silences gcc 8.1.1's warning that the size of the source was being used, not the destination. The destination has just been allocated to be the size of the source so no overflow can occur. Move existing variable that later holds the buffer size to before the allocation and strncpy so it can be used for those too. --- diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 61bf7965..86a1f41d 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1078,8 +1078,9 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) formatproc != NULL) { filterbody(c1, buf, sizeof(buf), state, gstate); } else { - holder.c_text = mh_xmalloc (sizeof(buf)); - strncpy (holder.c_text, buf, sizeof(buf)); + bufsz = sizeof buf; + holder.c_text = mh_xmalloc(bufsz); + strncpy(holder.c_text, buf, bufsz); while (state == BODY) { putcomp (c1, &holder, BODYCOMP); bufsz = sizeof buf;