forked from kyonshi/grenzland-mud
Gcc 9.2.1 warnings (#87)
* Make sure all followers are free'd before freeing the character list Otherwise, the followers structs will point to free'd memory and the stop_follower call will attempt to dereference a free'd characters' followers list. * fix gcc warning: truncation in strncat In file included from /usr/include/string.h:494, from sysdep.h:74, from act.item.c:12: In function ‘strncat’, inlined from ‘name_from_drinkcon’ at act.item.c:804:5, inlined from ‘name_from_drinkcon’ at act.item.c:769:6: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:136:10: warning: ‘__builtin_strncat’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 136 | return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ act.item.c: In function ‘name_from_drinkcon’: act.item.c:797:16: note: length computed here 797 | cpylen = strlen(cur_name); | ^~~~~~~~~~~~~~~~ * Whitespace cleanup before bugfix * Fix warnings for gcc-9.2.1 Also, fixed an ancient FIXME and a known bad strcat usage. spell_parser.c: In function ‘say_spell’: spell_parser.c:135:75: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 216 [-Wformat-truncation=] 135 | snprintf(buf1, sizeof(buf1), "$n stares at you and utters the words, '%s'.", | ^~ In file included from /usr/include/stdio.h:867, from sysdep.h:69, from spell_parser.c:12: /usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: ‘__builtin___snprintf_chk’ output between 43 and 298 bytes into a destination of size 256
This commit is contained in:
@@ -770,7 +770,7 @@ void name_from_drinkcon(struct obj_data *obj)
|
||||
{
|
||||
char *new_name, *cur_name, *next;
|
||||
const char *liqname;
|
||||
int liqlen, cpylen;
|
||||
int liqlen, cpylen, maxlen;
|
||||
|
||||
if (!obj || (GET_OBJ_TYPE(obj) != ITEM_DRINKCON && GET_OBJ_TYPE(obj) != ITEM_FOUNTAIN))
|
||||
return;
|
||||
@@ -785,7 +785,8 @@ void name_from_drinkcon(struct obj_data *obj)
|
||||
}
|
||||
|
||||
liqlen = strlen(liqname);
|
||||
CREATE(new_name, char, strlen(obj->name) - strlen(liqname)); /* +1 for NUL, -1 for space */
|
||||
maxlen = strlen(obj->name) - strlen(liqname); /* +1 for NUL, -1 for space */
|
||||
CREATE(new_name, char, maxlen);
|
||||
|
||||
for (cur_name = obj->name; cur_name; cur_name = next) {
|
||||
if (*cur_name == ' ')
|
||||
@@ -799,9 +800,13 @@ void name_from_drinkcon(struct obj_data *obj)
|
||||
if (!strn_cmp(cur_name, liqname, liqlen))
|
||||
continue;
|
||||
|
||||
if (*new_name)
|
||||
if (*new_name) {
|
||||
strcat(new_name, " "); /* strcat: OK (size precalculated) */
|
||||
strncat(new_name, cur_name, cpylen); /* strncat: OK (size precalculated) */
|
||||
maxlen--;
|
||||
}
|
||||
|
||||
strncat(new_name, cur_name, maxlen); /* strncat: OK (size precalculated) */
|
||||
maxlen -= cpylen;
|
||||
}
|
||||
|
||||
if (GET_OBJ_RNUM(obj) == NOTHING || obj->name != obj_proto[GET_OBJ_RNUM(obj)].name)
|
||||
|
||||
Reference in New Issue
Block a user