kconfig: mconf,nconf: remove unneeded '\0' termination after snprintf()
PATCH 1/5 kconfig: mconf,nconf: remove unneeded '\0' termination after snprintf()
snprintf() always terminates the destination buffer with '\0' even if the buffer is not long enough. (In this case, the last element of the buffer becomes '\0'.)
The explicit termination is unneeded.
---
scripts/kconfig/mconf.c | 11 +++-------- scripts/kconfig/nconf.c | 12 +++--------- 2 files changed, 6 insertions(+), 17 deletions(-)
scripts/kconfig/mconf.c +3 -8
@@ -299,17 +299,12 @@ static char filename[PATH_MAX+1];static void set_config_filename (const char *config_filename) {static char menu_backtitle[PATH_MAX +128 ]; -int size; - size =snprintf (menu_backtitle,sizeof (menu_backtitle), -"%s - %s" , config_filename, rootmenu.prompt->text); -if (size >=sizeof (menu_backtitle)) - menu_backtitle[sizeof (menu_backtitle)-1 ] ='\0' ; +snprintf (menu_backtitle,sizeof (menu_backtitle),"%s - %s" , + config_filename, rootmenu.prompt->text);set_dialog_backtitle (menu_backtitle); - size =snprintf (filename,sizeof (filename),"%s" , config_filename); -if (size >=sizeof (filename)) - filename[sizeof (filename)-1 ] ='\0' ; +snprintf (filename,sizeof (filename),"%s" , config_filename); }struct subtitle_part {
scripts/kconfig/nconf.c +3 -9
@@ -635,16 +635,10 @@ static char filename[PATH_MAX+1];static char menu_backtitle[PATH_MAX +128 ];static const char *set_config_filename (const char *config_filename) { -int size; +snprintf (menu_backtitle,sizeof (menu_backtitle),"%s - %s" , + config_filename, rootmenu.prompt->text); - size =snprintf (menu_backtitle,sizeof (menu_backtitle), -"%s - %s" , config_filename, rootmenu.prompt->text); -if (size >=sizeof (menu_backtitle)) - menu_backtitle[sizeof (menu_backtitle)-1 ] ='\0' ; - - size =snprintf (filename,sizeof (filename),"%s" , config_filename); -if (size >=sizeof (filename)) - filename[sizeof (filename)-1 ] ='\0' ; +snprintf (filename,sizeof (filename),"%s" , config_filename);return menu_backtitle; }
Signature · 1 line
2.27.0
PATCH 2/5 kconfig: nconf: fix NORMAL attributes
The lower 8-bit of attributes should be 0, but this code wrongly sets it to NORMAL (=1). The correct one is A_NORMAL.
---
scripts/kconfig/nconf.gui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/kconfig/nconf.gui.c +2 -2
@@ -70,7 +70,7 @@ static void normal_color_theme(void)/* automatically add color... */ #define mkattr (name, attr) do { \ attributes[name] = attr | COLOR_PAIR(name); } while (0) -mkattr (NORMAL ,NORMAL ); +mkattr (NORMAL ,A_NORMAL );mkattr (MAIN_HEADING ,A_BOLD |A_UNDERLINE );mkattr (MAIN_MENU_FORE ,A_REVERSE );
@@ -102,7 +102,7 @@ static void no_colors_theme(void)/* automatically add highlight, no color */ #define mkattrn (name, attr) { attributes[name] = attr; } -mkattrn (NORMAL ,NORMAL ); +mkattrn (NORMAL ,A_NORMAL );mkattrn (MAIN_HEADING ,A_BOLD |A_UNDERLINE );mkattrn (MAIN_MENU_FORE ,A_STANDOUT );
Signature · 1 line
2.27.0
PATCH 3/5 kconfig: nconf: get rid of (void) casts from wattrset() calls
In reply to Masahiro YamadaThis reverts commit 10175ba65fde ("nconfig: Silence unused return values from wattrset").
With recent GCC versions used, I no longer see "value computed is not used" warnings even without the (void) casts.
The wattrset() used to be a macro like this:
#define wattrset(win,at) \
(NCURSES_OK_ADDR(win) \
? ((win)->_attrs = NCURSES_CAST(attr_t, at), \
OK) \
: ERR)The GCC bugzilla [1] reported a false-positive -Wunused-value warning in a similar test case. It was fixed by GCC 4.4.1.
Let's revert that commit, and see if somebody will claim the issue.
[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39889
---
scripts/kconfig/nconf.c | 14 +++++++------- scripts/kconfig/nconf.gui.c | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-)
scripts/kconfig/nconf.c +7 -7
@@ -370,18 +370,18 @@ static void print_function_line(void)int lines =getmaxy (stdscr);for (i =0 ; i < function_keys_num; i++) { - (void )wattrset (main_window, attributes[FUNCTION_HIGHLIGHT ]); +wattrset (main_window, attributes[FUNCTION_HIGHLIGHT ]);mvwprintw (main_window, lines-3 , offset,"%s" , function_keys[i].key_str); - (void )wattrset (main_window, attributes[FUNCTION_TEXT ]); +wattrset (main_window, attributes[FUNCTION_TEXT ]); offset +=strlen (function_keys[i].key_str);mvwprintw (main_window, lines-3 , offset,"%s" , function_keys[i].func); offset +=strlen (function_keys[i].func) + skip; } - (void )wattrset (main_window, attributes[NORMAL ]); +wattrset (main_window, attributes[NORMAL ]); }/* help */
@@ -956,16 +956,16 @@ static void show_menu(const char *prompt, const char *instructions, current_instructions = instructions;clear (); - (void )wattrset (main_window, attributes[NORMAL ]); +wattrset (main_window, attributes[NORMAL ]);print_in_middle (stdscr,1 ,0 ,getmaxx (stdscr), menu_backtitle, attributes[MAIN_HEADING ]); - (void )wattrset (main_window, attributes[MAIN_MENU_BOX ]); +wattrset (main_window, attributes[MAIN_MENU_BOX ]);box (main_window,0 ,0 ); - (void )wattrset (main_window, attributes[MAIN_MENU_HEADING ]); +wattrset (main_window, attributes[MAIN_MENU_HEADING ]);mvwprintw (main_window,0 ,3 ," %s " , prompt); - (void )wattrset (main_window, attributes[NORMAL ]); +wattrset (main_window, attributes[NORMAL ]);set_menu_items (curses_menu, curses_menu_items);
scripts/kconfig/nconf.gui.c +10 -10
@@ -167,7 +167,7 @@ void print_in_middle(WINDOW *win, length =strlen (string); temp = (width - length) /2 ; x = startx + (int )temp; - (void )wattrset (win, color); +wattrset (win, color);mvwprintw (win, y, x,"%s" , string);refresh (); }
@@ -297,11 +297,11 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)set_menu_fore (menu, attributes[DIALOG_MENU_FORE ]);set_menu_back (menu, attributes[DIALOG_MENU_BACK ]); - (void )wattrset (win, attributes[DIALOG_BOX ]); +wattrset (win, attributes[DIALOG_BOX ]);box (win,0 ,0 );/* print message */ - (void )wattrset (msg_win, attributes[DIALOG_TEXT ]); +wattrset (msg_win, attributes[DIALOG_TEXT ]);fill_window (msg_win, msg);set_menu_win (menu, win);
@@ -405,16 +405,16 @@ int dialog_inputbox(WINDOW *main_window, form_win =derwin (win,1 , prompt_width, prompt_lines+3 ,2 );keypad (form_win, TRUE); - (void )wattrset (form_win, attributes[INPUT_FIELD ]); +wattrset (form_win, attributes[INPUT_FIELD ]); - (void )wattrset (win, attributes[INPUT_BOX ]); +wattrset (win, attributes[INPUT_BOX ]);box (win,0 ,0 ); - (void )wattrset (win, attributes[INPUT_HEADING ]); +wattrset (win, attributes[INPUT_HEADING ]);if (title)mvwprintw (win,0 ,3 ,"%s" , title);/* print message */ - (void )wattrset (prompt_win, attributes[INPUT_TEXT ]); +wattrset (prompt_win, attributes[INPUT_TEXT ]);fill_window (prompt_win, prompt);mvwprintw (form_win,0 ,0 ,"%*s" , prompt_width," " );
@@ -576,7 +576,7 @@ void show_scroll_win(WINDOW *main_window,/* create the pad */ pad =newpad (total_lines+10 , total_cols+10 ); - (void )wattrset (pad, attributes[SCROLLWIN_TEXT ]); +wattrset (pad, attributes[SCROLLWIN_TEXT ]);fill_window (pad, text); win_lines =min (total_lines+4 , lines-2 );
@@ -591,9 +591,9 @@ void show_scroll_win(WINDOW *main_window, win =newwin (win_lines, win_cols, y, x);keypad (win, TRUE);/* show the help in the help window, and show the help panel */ - (void )wattrset (win, attributes[SCROLLWIN_BOX ]); +wattrset (win, attributes[SCROLLWIN_BOX ]);box (win,0 ,0 ); - (void )wattrset (win, attributes[SCROLLWIN_HEADING ]); +wattrset (win, attributes[SCROLLWIN_HEADING ]);mvwprintw (win,0 ,3 ," %s " , title); panel =new_panel (win);
Signature · 1 line
2.27.0
PATCH 5/5 kconfig: nconf: refactor attributes setup code
In reply to Masahiro YamadaThe current attributes setup code is strange; the array attribute[] is set to values outside the range of the attribute_t enum.
At least,
attributes_t attributes[ATTR_MAX+1] = {0};... should be
int attribute[ATTR_MAX+1] = {0};Also, there is no need to hard-code the color-pair numbers in attributes_t.
The current code is horribly screwed up. Rewrite it.
---
scripts/kconfig/nconf.c | 22 ++-- scripts/kconfig/nconf.gui.c | 253 ++++++++++++++++-------------------- scripts/kconfig/nconf.h | 44 +++---- 3 files changed, 144 insertions(+), 175 deletions(-)
scripts/kconfig/nconf.c +11 -11
@@ -370,18 +370,18 @@ static void print_function_line(void)int lines =getmaxy (stdscr);for (i =0 ; i < function_keys_num; i++) { -wattrset (main_window, attributes[FUNCTION_HIGHLIGHT ]); +wattrset (main_window, attr_function_highlight);mvwprintw (main_window, lines-3 , offset,"%s" , function_keys[i].key_str); -wattrset (main_window, attributes[FUNCTION_TEXT ]); +wattrset (main_window, attr_function_text); offset +=strlen (function_keys[i].key_str);mvwprintw (main_window, lines-3 , offset,"%s" , function_keys[i].func); offset +=strlen (function_keys[i].func) + skip; } -wattrset (main_window, attributes[NORMAL ]); +wattrset (main_window, attr_normal); }/* help */
@@ -956,16 +956,16 @@ static void show_menu(const char *prompt, const char *instructions, current_instructions = instructions;clear (); -wattrset (main_window, attributes[NORMAL ]); +wattrset (main_window, attr_normal);print_in_middle (stdscr,1 ,0 ,getmaxx (stdscr), menu_backtitle, - attributes[MAIN_HEADING ]); + attr_main_heading); -wattrset (main_window, attributes[MAIN_MENU_BOX ]); +wattrset (main_window, attr_main_menu_box);box (main_window,0 ,0 ); -wattrset (main_window, attributes[MAIN_MENU_HEADING ]); +wattrset (main_window, attr_main_menu_heading);mvwprintw (main_window,0 ,3 ," %s " , prompt); -wattrset (main_window, attributes[NORMAL ]); +wattrset (main_window, attr_normal);set_menu_items (curses_menu, curses_menu_items);
@@ -1521,9 +1521,9 @@ int main(int ac, char **av)menu_opts_on (curses_menu,O_NONCYCLIC );menu_opts_on (curses_menu,O_IGNORECASE );set_menu_mark (curses_menu," " ); -set_menu_fore (curses_menu, attributes[MAIN_MENU_FORE ]); -set_menu_back (curses_menu, attributes[MAIN_MENU_BACK ]); -set_menu_grey (curses_menu, attributes[MAIN_MENU_GREY ]); +set_menu_fore (curses_menu, attr_main_menu_fore); +set_menu_back (curses_menu, attr_main_menu_back); +set_menu_grey (curses_menu, attr_main_menu_grey);set_config_filename (conf_get_configname ());setup_windows ();
scripts/kconfig/nconf.gui.c +113 -140
307 lines not on this page · raw message
scripts/kconfig/nconf.h +20 -24
50 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH 4/5 kconfig: nconf: remove unneeded default for menu prompt
In reply to Masahiro YamadaThe rootmenu always has a prompt even if the 'mainmenu' statement is missing in the top Kconfig file.
conf_parse() calls menu_add_prompt(P_MENU, "Main menu", NULL) in this case.
So, every 'menu' has a prompt.
---
scripts/kconfig/nconf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
scripts/kconfig/nconf.c +2 -4
@@ -1068,7 +1068,6 @@ static int do_match(int key, struct match_state *state, int *ans)static void conf (struct menu *menu) {struct menu *submenu =NULL ; -const char *prompt =menu_get_prompt (menu);struct symbol *sym;int res;int current_index =0 ;
@@ -1086,9 +1085,8 @@ static void conf(struct menu *menu)if (!child_count)break ; -show_menu (prompt ? prompt :"Main Menu" , - menu_instructions, - current_index, &last_top_row); +show_menu (menu_get_prompt (menu), menu_instructions, + current_index, &last_top_row);keypad ((menu_win (curses_menu)), TRUE);while (!global_exit) {if (match_state.in_search) {
Signature · 1 line
2.27.0