20.04 gcc with -O2 crashes due to previously benign error

Colin Watson cjwatson at ubuntu.com
Sun Jun 21 18:25:40 UTC 2020


On Sun, Jun 21, 2020 at 09:23:20AM -0700, David L wrote:
> The program below crashes when compiled with -O2 or greater optimization on
> Ubuntu 20.04 (it worked fine on at least 1[468].04. I know that it's my own
> fault for forgetting a return value and ignoring the compiler warning, but
> IMHO, this shouldn't result in a difficult to debug segfault. Shame on me
> for writing code with undefined behavior. Shame on gcc for a punishment not
> suited to the crime. ;) I write this in the hope that somebody else doesn't
> waste hours debugging a problem with a program that has run fine through
> many versions of gcc with a previously benign missing but ignored return
> value.
> 
> int init()
> {
> }
> int main(int argc, char *argv[])
> {
>   init();
>   return 0;
> }

I can't reproduce this crash, and I don't *think* the letter of the C
standard forbids this program (since the return value isn't used; see
C99 6.9.1(12)).  But it's quite possible it might depend on other
compiler options or details that you haven't told us; and in any case C
is a sufficiently unsafe language that I would consider it, er,
ambitious to ignore compiler warnings.  If you're writing C, take all
the static-analysis help you can get!

-- 
Colin Watson (he/him)                              [cjwatson at ubuntu.com]




More information about the ubuntu-users mailing list