[PATCH] style: label followed by a declaration is a C23 extension

761 views
Skip to first unread message

Michael Adler

unread,
Sep 17, 2024, 3:10:22 AM9/17/24
to swup...@googlegroups.com, Michael Adler, Christian Storm
Clang refuses to compile code with a label followed by a declaration, as
it is against the C standard specifications. This commit applies a
simple fix to ensure compatibility with the C standard.

Reported-by: Christian Storm <christi...@siemens.com>
Signed-off-by: Michael Adler <michae...@siemens.com>
Signed-off-by: Christian Storm <christi...@siemens.com>
---
core/swupdate.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/core/swupdate.c b/core/swupdate.c
index dc818599..d0633c69 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -538,7 +538,7 @@ int main(int argc, char **argv)
}
exit(EXIT_SUCCESS);
break;
- case 'E':
+ case 'E': {
int fd;
fd = open(optarg, O_RDONLY);
if (fd < 0)
@@ -551,6 +551,7 @@ int main(int argc, char **argv)
printf("%d\n", bootdev);
exit(EXIT_SUCCESS);
break;
+ }
case 'l':
loglevel = strtoul(optarg, NULL, 10);
break;
--
2.46.1

Stefano Babic

unread,
Sep 17, 2024, 3:38:57 AM9/17/24
to Michael Adler, swup...@googlegroups.com, Christian Storm
On 17.09.24 09:08, 'Michael Adler' via swupdate wrote:
> Clang refuses to compile code with a label followed by a declaration, as
> it is against the C standard specifications. This commit applies a
> simple fix to ensure compatibility with the C standard.
>

Well, then we can simply move "int fd" before the "switch (c)", then it
is C99.

It seems we should add a test case in CI with clang, I always use gcc
and I do not get these errors (and yes, I was aware of this, but as gcc
didn't complain, it was ok to me)..

Best regards,
Stefano

Michael Adler

unread,
Sep 19, 2024, 2:48:40 AM9/19/24
to Stefano Babic, swup...@googlegroups.com, Christian Storm
Hi Stefano,

> Well, then we can simply move "int fd" before the "switch (c)", then it
> is C99.

sure, I will send a v2.

> It seems we should add a test case in CI with clang, I always use gcc
> and I do not get these errors (and yes, I was aware of this, but as gcc
> didn't complain, it was ok to me)..

Agreed. I will send a separate patch series, as I've noticed a few more things
that could be improved in the CI setup while I'm at it. I need to correct
myself, though: at least with Clang 18, this issue is only a compiler warning.
It may have been different with Christian's older Clang version. Anyway, I
think it's a good idea to fix warnings in general.

Kind Regards,
Michael

--
Michael Adler

Siemens AG
Technology
Connectivity & Edge
Open Source Embedded Systems
T CED OES-DE
Friedrich-Ludwig-Bauer-Str. 3
85748 Garching, Germany

Siemens Aktiengesellschaft: Chairman of the Supervisory Board: Jim Hagemann
Snabe; Managing Board: Roland Busch, Chairman, President and Chief Executive
Officer; Cedrik Neike, Matthias Rebellius, Ralf P. Thomas, Judith Wiese;
Registered offices: Berlin and Munich, Germany; Commercial registries:
Berlin-Charlottenburg, HRB 12300, Munich, HRB 6684; WEEE-Reg.-No. DE 23691322

Michael Adler

unread,
Sep 19, 2024, 2:48:42 AM9/19/24
to swup...@googlegroups.com, Michael Adler, Christian Storm
This fixes a (clang) compiler warning.

Reported-by: Christian Storm <christi...@siemens.com>
Signed-off-by: Michael Adler <michae...@siemens.com>
Signed-off-by: Christian Storm <christi...@siemens.com>
---
core/swupdate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/swupdate.c b/core/swupdate.c
index dc818599..ddb6ffe1 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -522,6 +522,7 @@ int main(int argc, char **argv)
* Parse once the command line just to find if a
* configuration file is passed
*/
+ int fd;
while ((c = getopt_long(argc, argv, main_options,
long_options, NULL)) != EOF) {
switch (c) {
@@ -539,7 +540,6 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case 'E':
- int fd;
fd = open(optarg, O_RDONLY);
if (fd < 0)
exit(EXIT_FAILURE);
--
2.46.1

Stefano Babic

unread,
Sep 20, 2024, 3:27:41 AM9/20/24
to Michael Adler, swup...@googlegroups.com, Christian Storm
Applied to -master, thanks !

Best regards,
Stefano Babic
Reply all
Reply to author
Forward
0 new messages