Joreg (joreg) wrote,
Joreg
joreg

Code WTF 3

#include <stdio.h>

typedef int (*Function)();

static Function Do;

static int EraseAll() {
	printf ("rm -rf /\n");
	return 0;
}

void NeverCalled() {
	Do = EraseAll;
}

int main() {
	return Do();
}

clang++ -O1 test.cpp -o test.exe && test.exe

rm -rf /
Also, more dangerous UB handling of clang (compared to gcc)
Tags: c++
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 5 comments