-
Notifications
You must be signed in to change notification settings - Fork 0
Undefined Behaviour
MarekBykowski edited this page May 26, 2026
·
1 revision
| # | Name | What happens | Fix |
|---|---|---|---|
| ☠ | Signed overflow |
INT_MAX + 1 — compiler may remove checks |
use unsigned or check before |
| ☠ | Strict aliasing |
*(uint32_t*)&float_var — wrong value at -O2
|
use memcpy() or union
|
| ☠ | No sequence point |
printf("%d %d", *p++, *p++) — anything goes |
one *p++ per statement |
| ☠ | Null deref before check |
*p = 42; if(p==NULL) — branch eliminated |
check before deref |
// ; is a sequence point — side effects committed before next statement
printf("%d ", *p++); // ok — p++ committed after ;
printf("%d ", *p++); // ok — p already advanced
printf("%d\n", *p); // ok — no modification