public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104367] New: Possible improvements for -Wmisleading-indentation
@ 2022-02-03 12:20 frantisek at sumsal dot cz
  2022-02-03 12:23 ` [Bug c/104367] " marxin at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: frantisek at sumsal dot cz @ 2022-02-03 12:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104367

            Bug ID: 104367
           Summary: Possible improvements for -Wmisleading-indentation
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: frantisek at sumsal dot cz
  Target Milestone: ---

Hello!

Recently we encountered a pretty nasty bug in systemd[0], which makes me wonder
if this situation couldn't be prevented by throwing a compiler warning.

# cat /etc/redhat-release 
Fedora release 36 (Rawhide)
# gcc --version
gcc (GCC) 12.0.1 20220125 (Red Hat 12.0.1-0)

Reproducer:
#include <stdio.h>

void bar(int *x) {
    printf("%d\n", *x);
}

void foo(int *x) {
    if (!x)
        return

    bar(x);
}

int main(void) {
    foo(NULL);

    return 0;
}


The culprit here is, obviously, the missing semicolon after the return
statement, which currently leads to a segmentation fault:

# gcc -Wall -Wextra -Wmisleading-indentation -o main main.c
# ./main 
Segmentation fault (core dumped)

That is, however, silently accepted, since the resulting expression (return
bar(x);) is still valid in this context.

I wonder if this couldn't/shouldn't be detected by -Wmisleading-indentation
(since this definitely falls into that category).

Possibly related to other similar bugs like:
 - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66298
 - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70968
 - and others

[0] https://github.com/systemd/systemd/pull/22387/files

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-04  0:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03 12:20 [Bug c/104367] New: Possible improvements for -Wmisleading-indentation frantisek at sumsal dot cz
2022-02-03 12:23 ` [Bug c/104367] " marxin at gcc dot gnu.org
2022-02-03 21:28 ` msebor at gcc dot gnu.org
2022-02-04  0:06 ` [Bug c++/104367] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).