From: "levi.yun" <yeoreum.yun@arm.com>
To: devel@edk2.groups.io
Cc: yeoreum.yun@arm.com, sami.mujawar@arm.com,
pierre.gondois@arm.com, rebecca@bsdio.com,
gaoliming@byosoft.com.cn, bob.c.feng@intel.com,
yuwei.chen@intel.com, nd@arm.com
Subject: [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation
Date: Mon, 15 Apr 2024 19:59:47 +0100 [thread overview]
Message-ID: <20240415185947.160172-1-yeoreum.yun@arm.com> (raw)
If a global variable is initialised using a macro with multiple
arguments, ECC incorrectly parses the statement and reports the
macro arguments as variable declarations.
Example: In the following statement:
STATIC INT WrongVariable = MACRO_VERSION(1, 0), NextVariable;
The logic in the ECC function GetIdentifierList() interprets the
above statement as declaration of three variables:
1. 'WrongVariable = MACRO_VERSION(1,'
2. '0)'
3. 'NextVariable'
Following which NamingConventionCheckVariableName() reports an
error for "0)" stating an incorrect variable declaration as
below:
"ERROR - *The variable name [0)] does not follow the rules"
This patch fixes the parsing logic so that scenarios with macro
initialisations are handled correctly.
Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Pierre Gondois <pierre.gondois@arm.com>
Signed-off-by: levi.yun <yeoreum.yun@arm.com>
---
The changes can be seen at https://github.com/LeviYeoReum/edk2/tree/levi/3057_fix_false_on_ecc_v2
BaseTools/Source/Python/Ecc/c.py | 23 ++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/BaseTools/Source/Python/Ecc/c.py b/BaseTools/Source/Python/Ecc/c.py
index 61ad084fcc5b85b5a2194afd8bb1a4b4b65fdaee..71dc0fcf884ee3d45a527f20844b697958df366c 100644
--- a/BaseTools/Source/Python/Ecc/c.py
+++ b/BaseTools/Source/Python/Ecc/c.py
@@ -182,8 +182,27 @@ def GetIdentifierList():
continue
if var.Declarator.find('{') == -1:
- for decl in var.Declarator.split(','):
- DeclList = decl.split('=')
+ DeclText = var.Declarator
+ while (len(DeclText) > 0):
+ AllocatorPos = DeclText.find('=')
+ SplitPos = DeclText.find(',')
+
+ if (SplitPos == -1):
+ SplitPos = len(DeclText)
+ elif (SplitPos > AllocatorPos):
+ NextAllcatorPos = DeclText.find('=', AllocatorPos + 1)
+ if (NextAllcatorPos == -1):
+ NextAllcatorPos = len(DeclText)
+ ParPos = DeclText.rfind(')', SplitPos, NextAllcatorPos)
+ if (ParPos != -1):
+ SplitPos = DeclText.find(',', ParPos)
+ if (SplitPos == -1):
+ SplitPos = ParPos + 1
+
+ SubDeclText = DeclText[:SplitPos]
+ DeclText = DeclText[SplitPos + 1:]
+
+ DeclList = SubDeclText.split('=')
Name = DeclList[0].strip()
if ArrayPattern.match(Name):
LSBPos = var.Declarator.find('[')
--
Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117802): https://edk2.groups.io/g/devel/message/117802
Mute This Topic: https://groups.io/mt/105542888/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next reply other threads:[~2024-04-15 18:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 18:59 levi.yun [this message]
2024-04-16 3:51 ` [edk2-devel] [PATCH 1/1] BaseTool/Ecc: Fix incorrect parsing of variable initialisation Sami Mujawar
2024-04-17 6:33 ` 回复: " gaoliming via groups.io
2024-04-16 7:37 ` PierreGondois
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-list 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=20240415185947.160172-1-yeoreum.yun@arm.com \
--to=devel@edk2.groups.io \
/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