From: Li zeming <zeming@nfschina.com>
To: masahiroy@kernel.org
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
Li zeming <zeming@nfschina.com>
Subject: [PATCH] lxdialog: menubox: Add malloc allocation judgment
Date: Mon, 24 Oct 2022 13:56:29 +0800 [thread overview]
Message-ID: <20221024055629.178198-1-zeming@nfschina.com> (raw)
Add menu_item Only when the pointer judges that the pointer is valid
can function code be executed.
Signed-off-by: Li zeming <zeming@nfschina.com>
---
| 53 +++++++++++++++---------------
1 file changed, 27 insertions(+), 26 deletions(-)
--git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index 58c2f8afe59b..2ae263ad477e 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -55,34 +55,35 @@ static void do_print_item(WINDOW * win, const char *item, int line_y,
{
int j;
char *menu_item = malloc(menu_width + 1);
+ if (menu_item) {
+ strncpy(menu_item, item, menu_width - item_x);
+ menu_item[menu_width - item_x] = '\0';
+ j = first_alpha(menu_item, "YyNnMmHh");
- strncpy(menu_item, item, menu_width - item_x);
- menu_item[menu_width - item_x] = '\0';
- j = first_alpha(menu_item, "YyNnMmHh");
-
- /* Clear 'residue' of last item */
- wattrset(win, dlg.menubox.atr);
- wmove(win, line_y, 0);
-#if OLD_NCURSES
- {
- int i;
- for (i = 0; i < menu_width; i++)
- waddch(win, ' ');
- }
-#else
- wclrtoeol(win);
-#endif
- wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
- mvwaddstr(win, line_y, item_x, menu_item);
- if (hotkey) {
- wattrset(win, selected ? dlg.tag_key_selected.atr
- : dlg.tag_key.atr);
- mvwaddch(win, line_y, item_x + j, menu_item[j]);
- }
- if (selected) {
- wmove(win, line_y, item_x + 1);
+ /* Clear 'residue' of last item */
+ wattrset(win, dlg.menubox.atr);
+ wmove(win, line_y, 0);
+ #if OLD_NCURSES
+ {
+ int i;
+ for (i = 0; i < menu_width; i++)
+ waddch(win, ' ');
+ }
+ #else
+ wclrtoeol(win);
+ #endif
+ wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
+ mvwaddstr(win, line_y, item_x, menu_item);
+ if (hotkey) {
+ wattrset(win, selected ? dlg.tag_key_selected.atr
+ : dlg.tag_key.atr);
+ mvwaddch(win, line_y, item_x + j, menu_item[j]);
+ }
+ if (selected) {
+ wmove(win, line_y, item_x + 1);
+ }
+ free(menu_item);
}
- free(menu_item);
wrefresh(win);
}
--
2.18.2
next reply other threads:[~2022-10-24 5:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 5:56 Li zeming [this message]
2022-10-24 8:11 ` Bagas Sanjaya
2022-10-24 9:39 ` Li zeming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221024055629.178198-1-zeming@nfschina.com \
--to=zeming@nfschina.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masahiroy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®