From patchwork Mon Oct 24 05:42:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li zeming X-Patchwork-Id: 8165 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp269489wru; Sun, 23 Oct 2022 22:46:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5qv0JnYDEtU/qolwKlqE5gy+NcMFtvN3um7ElstUAZWucCmTkbgkXHXlYyw7ms81UFmaT0 X-Received: by 2002:a63:8ac8:0:b0:46e:c3dd:69df with SMTP id y191-20020a638ac8000000b0046ec3dd69dfmr12082862pgd.539.1666590384600; Sun, 23 Oct 2022 22:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666590384; cv=none; d=google.com; s=arc-20160816; b=h6dY1LmzA0UV8ckR7prfM3Gyt+uz0jhT1SmGOc0hfur+Np60aYsjekp+U7t9XyOaDu ceUVBDxdQhGYxwg2Lswe/bND+zgWm8hn0q5nfYJrceohRKiDXAbSFuo+ypI7+hVCqfWn /yDFO7Y+ylHrFdfHzjfZgE9ds6QaewlZdRjVdS9k5sh1cvuAnJq7b2dR1eaA9PnD/Yd1 O56betjOZIIVWYyNKSLcuSGIlwrsCr0iYYKn2FRWZQTNQQDD69kJC5U3P1lug25ivvzy M6k2FIQA47f9xfCdXVH7OMUPwKNfuaRb6zrHYKjAjAekx06MRyHL7vttrrKzBOfuCjuZ an3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=58N+XU/JAntkaSq8jTbK3dNm0n44VbRVo46jqn8NQkM=; b=yyXawkMcNwWEob40iFN+ohcFhJ2AG4Q/i3AXuci2hcUcikuEVP8Z9wK5uDef77frbz uT/td6ljeyrxElaVqD3fX5zylghHrakv1Qbv22arAGzDG6hphqJZkZR66xCqnpylYTb5 J6VCKI8Qd17Yfe7SJYYXeyq8s3jBLRxptBnwDzUe78nDlQkhfk7BVOkBxuTLu6Po0N0A eDjjyub6rew8EBkZm4Xx+Fud5lGdcm6Q2gVvBMmkUBIfF1B+Hhlmfg45og+ZVaSb+NIi DvB1HkNOMo2jvhh7NIT660QLAN3I2qUmb2q/ae9DeyyAzQQNZQJ4yC6IYy1H15mQJGu2 4I7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f6-20020a17090a9b0600b0020319d3bb7bsi13482054pjp.18.2022.10.23.22.46.11; Sun, 23 Oct 2022 22:46:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230048AbiJXFms (ORCPT + 99 others); Mon, 24 Oct 2022 01:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230045AbiJXFml (ORCPT ); Mon, 24 Oct 2022 01:42:41 -0400 Received: from mail.nfschina.com (unknown [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2603A74E0A; Sun, 23 Oct 2022 22:42:40 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 302A51E80D74; Mon, 24 Oct 2022 13:41:11 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yJ82tyFT3FOp; Mon, 24 Oct 2022 13:41:08 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: zeming@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 7CE4B1E80CA5; Mon, 24 Oct 2022 13:41:08 +0800 (CST) From: Li zeming To: masahiroy@kernel.org Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Li zeming Subject: [PATCH] lxdialog: checklist: Add malloc allocation judgment Date: Mon, 24 Oct 2022 13:42:22 +0800 Message-Id: <20221024054222.177899-1-zeming@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747546679156952243?= X-GMAIL-MSGID: =?utf-8?q?1747546679156952243?= Add list_item Only when the pointer judges that the pointer is valid can function code be executed. Signed-off-by: Li zeming --- scripts/kconfig/lxdialog/checklist.c | 45 ++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c index fd161cfff121..61a8f86fe467 100644 --- a/scripts/kconfig/lxdialog/checklist.c +++ b/scripts/kconfig/lxdialog/checklist.c @@ -19,29 +19,30 @@ static void print_item(WINDOW * win, int choice, int selected) { int i; char *list_item = malloc(list_width + 1); + if (list_item) { + strncpy(list_item, item_str(), list_width - item_x); + list_item[list_width - item_x] = '\0'; - strncpy(list_item, item_str(), list_width - item_x); - list_item[list_width - item_x] = '\0'; - - /* Clear 'residue' of last item */ - wattrset(win, dlg.menubox.atr); - wmove(win, choice, 0); - for (i = 0; i < list_width; i++) - waddch(win, ' '); - - wmove(win, choice, check_x); - wattrset(win, selected ? dlg.check_selected.atr - : dlg.check.atr); - if (!item_is_tag(':')) - wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' '); - - wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr); - mvwaddch(win, choice, item_x, list_item[0]); - wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); - waddstr(win, list_item + 1); - if (selected) { - wmove(win, choice, check_x + 1); - wrefresh(win); + /* Clear 'residue' of last item */ + wattrset(win, dlg.menubox.atr); + wmove(win, choice, 0); + for (i = 0; i < list_width; i++) + waddch(win, ' '); + + wmove(win, choice, check_x); + wattrset(win, selected ? dlg.check_selected.atr + : dlg.check.atr); + if (!item_is_tag(':')) + wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' '); + + wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr); + mvwaddch(win, choice, item_x, list_item[0]); + wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); + waddstr(win, list_item + 1); + if (selected) { + wmove(win, choice, check_x + 1); + wrefresh(win); + } } free(list_item); }