Skip to content

Instantly share code, notes, and snippets.

@furkanusta
Created November 6, 2018 20:11
Show Gist options
  • Save furkanusta/f9b6d9b0774e51e7b83287eb8bfbbfd1 to your computer and use it in GitHub Desktop.
Save furkanusta/f9b6d9b0774e51e7b83287eb8bfbbfd1 to your computer and use it in GitHub Desktop.
Undefined Behavior
// 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