-
-
Save bcantrill/7b30914541fe6c3306fc174992d497ec to your computer and use it in GitHub Desktop.
Punishment doesn't fit the crime?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define NULL ((void *)0) | |
static char *arr[2] = { "nasal", "demons" }; | |
long | |
func() | |
{ | |
int i; | |
for (i = 0; i <= 2; i++) { | |
if (arr[i] == NULL && i == 0) | |
return (0xbad); | |
} | |
return (0xfad); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More weird example (https://godbolt.org/z/VM3nMo):
results into:
As one could see the UB is abruptly "conditional" (in
func_control
) if one extend it with control-switch.And as already said, what on this UB is unexpected for developer (sorry for tautology):
array subscript 2 is above array bounds of 'char *[2]' [-Warray-bounds]
.Even not with
-Wall
or-Wextra
;control
condition infunc_control
) change the UB drastically;Clear, it is an UB, but why this could not be a bit "stable" UB, remaining the same result between versions.