Resolve Wrestrict warnings on GCC 8.1.1 (#51)

* Fix several misleading indentation warnings on GCC 8.1.1

* Fix reliance on undefined strcpy/sprintf behavior (-Wrestrict warnings)

The standard states that strcpy results in undefined behavior when the source
and destination buffers overlap. I resolved this with a combination of memmove
and strlen. Note that the resulting code is slightly less efficient.

Similarly, sprintf's behavior is undefined when copying takes place between
objects that overlap. I replaced most of these with a simple strcat, though
one required a temp buffer.

* Fix format in improved-edit.c to match surrounding code
This commit is contained in:
Kevin Fischer
2018-07-14 13:11:47 -05:00
committed by wyld-sw
parent f9903c05b3
commit 5cca63a01c
4 changed files with 7 additions and 4 deletions

View File

@@ -1101,7 +1101,7 @@ static int read_type_list(FILE *shop_f, struct shop_buy_data *list,
for (tindex = 0; *item_types[tindex] != '\n'; tindex++)
if (!strn_cmp(item_types[tindex], buf, strlen(item_types[tindex]))) {
num = tindex;
strcpy(buf, buf + strlen(item_types[tindex])); /* strcpy: OK (always smaller) */
memmove(buf, buf + strlen(item_types[tindex]), strlen(buf) - strlen(item_types[tindex]) + 1);
break;
}