analyzer lint for win/curses/*.c

There is still an issue in cursmesg.c.

The last diff band (curses_putch) isn't related to static analysis.
This commit is contained in:
PatR
2025-01-23 13:52:19 -08:00
parent 29f7580fc1
commit 150b331189
4 changed files with 21 additions and 13 deletions

View File

@@ -449,7 +449,6 @@ curses_ext_cmd(void)
letter = pgetchar(); /* pgetchar(cmd.c) implements do-again */
curs_set(0);
prompt_width = (int) strlen(cur_choice);
matches = 0;
if (letter == '\033' || letter == ERR) {
ret = -1;
@@ -667,7 +666,7 @@ curs_pad_menu(
boolean do_pad UNUSED)
{
nhmenu_item *menu_item_ptr;
int numpages = current_menu->num_pages;
int numpages;
/* caller has already called menu_win_size() */
menu_determine_pages(current_menu); /* sets 'menu->num_pages' */
@@ -942,7 +941,7 @@ menu_is_multipage(nhmenu *menu, int width, int height)
int curline = 0, accel_per_page = 0;
nhmenu_item *menu_item_ptr = menu->entries;
if (*menu->prompt) {
if (menu->prompt && *menu->prompt) {
curline += curses_num_lines(menu->prompt, width) + 1;
}
@@ -978,13 +977,12 @@ menu_determine_pages(nhmenu *menu)
int tmpline, num_lines, accel_per_page;
int curline = 0;
int page_num = 1;
nhmenu_item *menu_item_ptr = menu->entries;
nhmenu_item *menu_item_ptr;
int width = menu->width;
int height = menu->height;
int page_end = height;
if (*menu->prompt) {
if (menu->prompt && *menu->prompt) {
curline += curses_num_lines(menu->prompt, width) + 1;
}
tmpline = curline;
@@ -1032,6 +1030,7 @@ menu_win_size(nhmenu *menu)
int maxheaderwidth = menu->prompt ? (int) strlen(menu->prompt) : 0;
nhmenu_item *menu_item_ptr, *last_item_ptr = NULL;
#if 0 /* maxwidth is set below, so the value calculated here isn't used */
if (program_state.gameover) {
/* for final inventory disclosure, use full width */
maxwidth = term_cols - 2; /* +2: borders assumed */
@@ -1046,6 +1045,7 @@ menu_win_size(nhmenu *menu)
if ((term_cols / 2) > maxwidth)
maxwidth = (term_cols / 2); /* Half the screen */
}
#endif
maxheight = menu_max_height();
/* First, determine the width of the longest menu entry */
@@ -1475,8 +1475,6 @@ curs_nonselect_menu_action(
}
menu_item_ptr = menu_item_ptr->next_item;
}
menu_item_ptr = menu->entries;
break;
} /* case MENU_SEARCH */
default:
@@ -1500,7 +1498,7 @@ menu_get_selections(WINDOW *win, nhmenu *menu, int how)
int num_selected = 0;
boolean dismiss = FALSE;
char selectors[256], groupaccels[256];
nhmenu_item *menu_item_ptr = menu->entries;
nhmenu_item *menu_item_ptr;
activemenu = win;
menu_display_page(win, menu, curpage, selectors, groupaccels);

View File

@@ -932,6 +932,8 @@ mesg_add_line(const char *mline)
} else {
/* instead of discarding list element being forced out, reuse it */
current_mesg = first_mesg;
assert(current_mesg != NULL);
assert(current_mesg->str != NULL);
/* whenever new 'mline' is shorter, extra allocation size of the
original element will be frittered away, until eventually we'll
discard this 'str' and dupstr() a replacement; we could easily

View File

@@ -173,6 +173,7 @@ curses_status_update(
/* decode once instead of every time it's displayed */
status_vals[BL_GOLD][0] = ' ';
text = decode_mixed(&status_vals[BL_GOLD][1], text);
nhUse(text);
} else if ((fldidx == BL_HUNGER || fldidx == BL_CAP)
&& (!*text || !strcmp(text, " "))) {
/* fieldfmt[] is " %s"; avoid lone space when empty */

View File

@@ -508,20 +508,27 @@ curs_destroy_all_wins(void)
{
curses_count_window((char *) 0); /* clean up orphan */
#if 0 /* this works but confuses the static analyzer (from llvm-19,
* which reports "warning: Use of memory after it is freed") */
while (nhwids)
curses_del_wid(nhwids->nhwid);
#lse
while (nhwids) {
nethack_wid *tmpptr = nhwids;
curses_del_wid(tmpptr->nhwid);
}
#endif
}
/* Print a single character in the given window at the given coordinates */
void
#ifdef ENHANCED_SYMBOLS
curses_putch(winid wid, int x, int y, int ch,
#ifdef ENHANCED_SYMBOLS
struct unicode_representation *unicode_representation,
int color, int framecolor, int attr)
#else
curses_putch(winid wid, int x, int y, int ch, int color, int framecolor, int attr)
#endif
int color, int framecolor, int attr)
{
static boolean map_initted = FALSE;
int sx, sy, ex, ey;