Created
November 6, 2018 20:11
-
-
Save furkanusta/f9b6d9b0774e51e7b83287eb8bfbbfd1 to your computer and use it in GitHub Desktop.
Undefined Behavior
This file contains hidden or 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
// Calls rm -rf / | |
#include <cstdlib> | |
typedef int (*Function)(); | |
static Function Do; | |
static int EraseAll() { | |
return system("rm -rf /"); | |
} | |
void NeverCalled() { | |
Do = EraseAll; | |
} | |
int main() { | |
return Do(); | |
} | |
//-------------------------- | |
int table[4]; | |
bool exists_in_table(int v) | |
{ | |
for (int i = 0; i <= 4; i++) { | |
if (table[i] == v) return true; | |
} | |
return false; | |
} | |
//-------------------------- (clang) | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
int *p = (int*)malloc(sizeof(int)); | |
int *q = (int*)realloc(p, sizeof(int)); | |
*p = 1; | |
*q = 2; | |
if (p == q) | |
printf("%d %d\n", *p, *q); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment