Fix string truncation warnings (Wstringop-truncation) (#53)

This commit is contained in:
Kevin Fischer 2018-07-15 16:23:26 -05:00 committed by wyld-sw
parent ad88f94a46
commit 14855c273a
5 changed files with 16 additions and 8 deletions

View file

@ -1936,8 +1936,10 @@ void add_llog_entry(struct char_data *ch, int type) {
/* we didn't - make a new one */
if(llast == NULL) { /* no entry found, add ..error if close! */
CREATE(llast,struct last_entry,1);
strncpy(llast->username,GET_NAME(ch),16);
strncpy(llast->hostname,GET_HOST(ch),128);
strncpy(llast->username,GET_NAME(ch),15);
strncpy(llast->hostname,GET_HOST(ch),127);
llast->username[15]='\0';
llast->hostname[127]='\0';
llast->idnum=GET_IDNUM(ch);
llast->punique=GET_PREF(ch);
llast->time=time(0);
@ -2054,8 +2056,11 @@ ACMD(do_last)
num = atoi(arg);
if (num < 0)
num = 0;
} else
} else {
strncpy(name, arg, sizeof(name)-1);
name[sizeof(name) - 1] = '\0';
}
half_chop(argument, arg, argument);
}
}

View file

@ -169,9 +169,9 @@ ACMD(do_ban)
CREATE(ban_node, struct ban_list_element, 1);
strncpy(ban_node->site, site, BANNED_SITE_LENGTH); /* strncpy: OK (b_n->site:BANNED_SITE_LENGTH+1) */
ban_node->site[BANNED_SITE_LENGTH] = '\0';
for (nextchar = ban_node->site; *nextchar; nextchar++)
*nextchar = LOWER(*nextchar);
ban_node->site[BANNED_SITE_LENGTH] = '\0';
strncpy(ban_node->name, GET_NAME(ch), MAX_NAME_LENGTH); /* strncpy: OK (b_n->size:MAX_NAME_LENGTH+1) */
ban_node->name[MAX_NAME_LENGTH] = '\0';
ban_node->date = time(0);

View file

@ -1628,7 +1628,7 @@ void find_replacement(void *go, struct script_data *sc, trig_data *trig,
void var_subst(void *go, struct script_data *sc, trig_data *trig,
int type, char *line, char *buf)
{
char tmp[MAX_INPUT_LENGTH], repl_str[MAX_INPUT_LENGTH];
char tmp[MAX_INPUT_LENGTH], repl_str[MAX_INPUT_LENGTH - 1];
char *var = NULL, *field = NULL, *p = NULL;
char tmp2[MAX_INPUT_LENGTH];
char *subfield_p, subfield[MAX_INPUT_LENGTH];
@ -1722,4 +1722,5 @@ void var_subst(void *go, struct script_data *sc, trig_data *trig,
left -= len;
} /* else if *p .. */
} /* while *p .. */
}
buf[sizeof(buf) - 1] = '\0';
}

View file

@ -945,7 +945,8 @@ static int export_save_rooms(zone_rnum zrnum)
struct extra_descr_data *xdesc;
for (xdesc = room->ex_description; xdesc; xdesc = xdesc->next) {
strncpy(buf, xdesc->description, sizeof(buf));
strncpy(buf, xdesc->description, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
strip_cr(buf);
fprintf(room_file, "E\n"
"%s~\n"

View file

@ -365,7 +365,8 @@ int save_rooms(zone_rnum rzone)
struct extra_descr_data *xdesc;
for (xdesc = room->ex_description; xdesc; xdesc = xdesc->next) {
strncpy(buf, xdesc->description, sizeof(buf));
strncpy(buf, xdesc->description, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
strip_cr(buf);
fprintf(sf, "E\n"
"%s~\n"