[ prog / sol / mona ]

prog


How can we make C worse?

8 2024-09-22 03:33

Make infinite loops UB to squeeze out a few more cycles.

Oh wait

$ cat loop.c
#include <stdio.h>

void never_return() {
    while (1) {}
}

int main() {
    puts("should be printed");
    never_return();
    puts("never reached, right?");
}
$ clang-11 loop.c -O3 -o loop
$ ./loop
should be printed
Segmentation fault

Here's your main btw:

0000000000401140 <main>:
  401140:	50                   	push   rax
  401141:	bf 04 20 40 00       	mov    edi,0x402004
  401146:	e8 e5 fe ff ff       	call   401030 <puts@plt>

That's right, no ret!

"Fixed" in more recent versions for trivial loops at least. Dunno about other loops though, good luck!

10


VIP:

do not edit these