From patchwork Fri Jun 29 09:12:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Gouders X-Patchwork-Id: 10495907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7EA7E601C7 for ; Fri, 29 Jun 2018 09:13:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B9FD2979A for ; Fri, 29 Jun 2018 09:13:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BCC1297A6; Fri, 29 Jun 2018 09:13:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=2.0 tests=BAYES_00, DKIM_ADSP_DISCARD, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DA9B2979A for ; Fri, 29 Jun 2018 09:13:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935449AbeF2JN3 (ORCPT ); Fri, 29 Jun 2018 05:13:29 -0400 Received: from services.gouders.net ([141.101.32.176]:52273 "EHLO services.gouders.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934348AbeF2JN3 (ORCPT ); Fri, 29 Jun 2018 05:13:29 -0400 Received: from lena.gouders.net ([193.175.198.193]) (authenticated bits=0) by services.gouders.net (8.14.8/8.14.8) with ESMTP id w5T9D0x3019652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Fri, 29 Jun 2018 11:13:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gouders.net; s=gnet; t=1530263604; bh=KpC5T4g5P8MIIzGOGtcOIUGkLlnkv047KnHDqDF4sus=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QBVykLJmjivYP1uKvmmoIQFPPo1JUXGh4UF7tzTlxDCtUlqGKPCo2xhg6bQaTA6/G pv2yU4jQWVgowRXVhC8fASSwiOxN5N+bTRnWKolX9Las17fXxK1WpAsjw+vA566TTt vL1Vjt9O6Eulf4xt8UsZ+ov0rPXHSr6jqPDninGw= From: Dirk Gouders To: Masahiro Yamada Cc: Dirk Gouders , Linux Kbuild mailing list Subject: [PATCH v2 1/2] kconfig: expr_print(): print constant symbols within quotes Date: Fri, 29 Jun 2018 11:12:36 +0200 Message-Id: <20180629091237.16620-2-dirk@gouders.net> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180629091237.16620-1-dirk@gouders.net> References: <20180629091237.16620-1-dirk@gouders.net> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Motivation for this commit was the problem that xfwrite() uses assert() to ensure it does not operate on empty strings. This caused aborts when the dependency for an empty default string was printed. A possibility to fix this issue would be to print all string constants in quotes which has the positive effect that empty strings have a length of 2 and do not trigger aborts. But currently, constant symbols are typeless, so this patch implements a fix by identifying all constant symbols by the symbol flag SYMBOL_CONST and printing their names within quotes. Note: The symbols y, m and n are statically defined as constants in symbol.c and hence also printed within quotes. Kconfig files contain a mixture of those symbols specified within and without quotes and we cannot reproduce that after parsing. Also, the kconfig language allows for (semantically meant) constant string, int and hex symbols to be specified within quotes or without, which is OK as long as there is no other symbol that is something other than the constant symbol that was meant to be; the following Kconfig file tries to illustrate this: config a int "Meant to have default 5..." default 5 config 5 int "but this symbol plays games." default "7" This implementation reproduces exactly the described mixture from the Kconfig files, thus original data. Signed-off-by: Dirk Gouders --- scripts/kconfig/expr.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index e1a39e90841d..b36e94e36f84 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c @@ -1141,6 +1141,8 @@ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken) { + const char *quoted; + if (!e) { fn(data, NULL, "y"); return; @@ -1151,7 +1153,15 @@ void expr_print(struct expr *e, switch (e->type) { case E_SYMBOL: if (e->left.sym->name) - fn(data, e->left.sym, e->left.sym->name); + /* + * Print constant symbols within quotes + */ + if (e->left.sym->flags & SYMBOL_CONST) { + quoted = sym_escape_string_value(e->left.sym->name); + fn(data, e->left.sym, quoted); + free((void*)quoted); + } else + fn(data, e->left.sym, e->left.sym->name); else fn(data, NULL, ""); break;