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:
@@ -2593,7 +2593,7 @@ distance, int door)
|
|||||||
if (!*buf)
|
if (!*buf)
|
||||||
sprintf(buf, "You see %s", GET_NAME(i));
|
sprintf(buf, "You see %s", GET_NAME(i));
|
||||||
else
|
else
|
||||||
sprintf(buf, "%s%s", buf, GET_NAME(i));
|
strcat(buf, GET_NAME(i));
|
||||||
if (--count > 1)
|
if (--count > 1)
|
||||||
strcat(buf, ", ");
|
strcat(buf, ", ");
|
||||||
else if (count == 1)
|
else if (count == 1)
|
||||||
|
|||||||
@@ -476,7 +476,8 @@ static void script_syntax_highlighting(struct descriptor_data *d, char *string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buffer, "%s%s\tn\r\n", buffer, line);
|
strcat(buffer, line);
|
||||||
|
strcat(buffer, "\tn\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
page_string(d, buffer, TRUE);
|
page_string(d, buffer, TRUE);
|
||||||
|
|||||||
@@ -358,7 +358,9 @@ void parse_edit_action(int command, char *string, struct descriptor_data *d)
|
|||||||
s++;
|
s++;
|
||||||
temp = *s;
|
temp = *s;
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
sprintf(buf, "%s%4d: ", buf, (i - 1));
|
char buf3[8];
|
||||||
|
sprintf(buf3, "%4d: ", (i - 1));
|
||||||
|
strcat(buf, buf3);
|
||||||
strcat(buf, t);
|
strcat(buf, t);
|
||||||
*s = temp;
|
*s = temp;
|
||||||
t = s;
|
t = s;
|
||||||
|
|||||||
@@ -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++)
|
for (tindex = 0; *item_types[tindex] != '\n'; tindex++)
|
||||||
if (!strn_cmp(item_types[tindex], buf, strlen(item_types[tindex]))) {
|
if (!strn_cmp(item_types[tindex], buf, strlen(item_types[tindex]))) {
|
||||||
num = 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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user