curses static analyzer bits

This is mostly just adding some Null guards ahead of
code that was already dereferencing pointers, so there
should be no change in behavior.

Also adds one validation of an array index that was
drawing a complaint.
This commit is contained in:
nhmall
2023-12-29 10:38:37 -05:00
parent bed3b1d667
commit 9d32956616
3 changed files with 25 additions and 21 deletions
+8 -8
View File
@@ -1078,16 +1078,16 @@ menu_win_size(nhmenu *menu)
/* Possibly reduce height if only 1 page */ /* Possibly reduce height if only 1 page */
if (!menu_is_multipage(menu, maxwidth, maxheight)) { if (!menu_is_multipage(menu, maxwidth, maxheight)) {
menu_item_ptr = menu->entries; if ((menu_item_ptr = menu->entries) != 0) {
while (menu_item_ptr->next_item != NULL) {
menu_item_ptr = menu_item_ptr->next_item;
}
while (menu_item_ptr->next_item != NULL) { lastline = (menu_item_ptr->line_num) + menu_item_ptr->num_lines;
menu_item_ptr = menu_item_ptr->next_item;
}
lastline = (menu_item_ptr->line_num) + menu_item_ptr->num_lines; if (lastline < maxheight) {
maxheight = lastline;
if (lastline < maxheight) { }
maxheight = lastline;
} }
} }
+16 -13
View File
@@ -947,8 +947,8 @@ mesg_add_line(const char *mline)
++num_messages; ++num_messages;
} else { } else {
/* at capacity; old head is being removed */ /* at capacity; old head is being removed */
first_mesg = first_mesg->next_mesg; /* new head */ if ((first_mesg = first_mesg->next_mesg) != 0) /* new head */
first_mesg->prev_mesg = NULL; /* head has no prev_mesg */ first_mesg->prev_mesg = NULL; /* head has no prev_mesg */
} }
/* since 'current_mesg' might be reusing 'first_mesg' and has now /* since 'current_mesg' might be reusing 'first_mesg' and has now
become 'last_mesg', this update must be after head replacement */ become 'last_mesg', this update must be after head replacement */
@@ -1056,7 +1056,8 @@ curses_putmsghistory(const char *msg, boolean restoring_msghist)
however, we aren't only called when restoring history; however, we aren't only called when restoring history;
core uses putmsghistory() for other stuff during play core uses putmsghistory() for other stuff during play
and those messages should have a normal turn value */ and those messages should have a normal turn value */
last_mesg->turn = restoring_msghist ? (1L << 3) : gh.hero_seq; if (last_mesg) /* appease static analyzer */
last_mesg->turn = restoring_msghist ? (1L << 3) : gh.hero_seq;
#ifdef DUMPLOG #ifdef DUMPLOG
dumplogmsg(last_mesg->str); dumplogmsg(last_mesg->str);
#endif #endif
@@ -1072,18 +1073,20 @@ curses_putmsghistory(const char *msg, boolean restoring_msghist)
stashed messages as newly occurring ones is much simpler; stashed messages as newly occurring ones is much simpler;
we ignore the backlinks because the list is destroyed as it we ignore the backlinks because the list is destroyed as it
gets processed hence there can't be any other traversals */ gets processed hence there can't be any other traversals */
mesg = stash_head; if ((mesg = stash_head) != 0) {
stash_head = mesg->next_mesg; stash_head = mesg->next_mesg;
--stash_count; --stash_count;
mesg_turn = mesg->turn; mesg_turn = mesg->turn;
mesg_add_line(mesg->str); mesg_add_line(mesg->str);
/* added line became new tail */ /* added line became new tail */
last_mesg->turn = mesg_turn; if (last_mesg) /* appease static analyzer */
last_mesg->turn = mesg_turn;
#ifdef DUMPLOG #ifdef DUMPLOG
dumplogmsg(mesg->str); dumplogmsg(mesg->str);
#endif #endif
free((genericptr_t) mesg->str); free((genericptr_t) mesg->str);
free((genericptr_t) mesg); free((genericptr_t) mesg);
}
} }
initd = FALSE; /* reset */ initd = FALSE; /* reset */
} }
+1
View File
@@ -397,6 +397,7 @@ curses_str_remainder(const char *str, int width, int line_num)
if (last_space == 0) { /* No spaces found */ if (last_space == 0) { /* No spaces found */
last_space = count - 1; last_space = count - 1;
} }
assert(IndexOk(last_space, substr));
if (substr[last_space] == '\0') { if (substr[last_space] == '\0') {
break; break;
} }