Skip to content

Instantly share code, notes, and snippets.

@sklam
Created February 4, 2020 23:08
Show Gist options
  • Save sklam/4ec23be55f128e929f0ed2357b239b17 to your computer and use it in GitHub Desktop.
Save sklam/4ec23be55f128e929f0ed2357b239b17 to your computer and use it in GitHub Desktop.
/*
Compile this with:
$ clang -O3 do_no_evil.c && ./a.out
Reference http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html
*/
#include <stdio.h>
#include <stdlib.h>
static void (*WhatToDo)() = 0;
static void EvilThings() {
printf("Do Evil\n");
}
void DoNotDoThis() {
WhatToDo = EvilThings;
printf("Do Not Do This!\n");
// Fail Safe exit
exit(1); // Don't do this ever
}
void DoSomething() {
WhatToDo();
}
int main() {
DoSomething();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment