argtable3: fix buffer overrun

This bug was suddently triggered by Appveyor compilation and seems to make sense.

[-] CC argtable3.c

    inlined from 'arg_cat_option' at argtable3.c:4208:13,
    inlined from 'arg_print_syntax' at argtable3.c:4392:9:
argtable3.c:4149:11: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
 4149 |     *dest = 0;
      |     ~~~~~~^~~
argtable3.c: In function 'arg_print_syntax':
argtable3.c:4381:14: note: at offset 200 to object 'syntax' with size 200 declared here
 4381 |         char syntax[200] = "";
      |              ^~~~~~
This commit is contained in:
Philippe Teuwen 2020-05-10 23:59:42 +02:00
parent f3293c9dcd
commit 8a9c7d2efc

View file

@ -4135,7 +4135,8 @@ int arg_parse(int argc, char * *argv, void * *argtable) {
*/
static void arg_cat(char **pdest, const char *src, size_t *pndest) {
char *dest = *pdest;
char *end = dest + *pndest;
// PM3 fix: leave room for null terminate char
char *end = dest + *pndest - 1;
/*locate null terminator of dest string */
while (dest < end && *dest != 0)