Ver código fonte

Initial commit.

master
Ian Piumarta 4 meses atrás
commit
2f2d130c80
19 arquivos alterados com 2016 adições e 0 exclusões
  1. +29
    -0
      Makefile
  2. +0
    -0
      assert.h
  3. +14
    -0
      demofiles/Makefile
  4. +18
    -0
      demofiles/dangling-pointer.c
  5. +11
    -0
      demofiles/invalid-pointer.c
  6. +14
    -0
      demofiles/memory-leak.c
  7. +13
    -0
      demofiles/multiple-free.c
  8. +9
    -0
      demofiles/null-pointer.c
  9. +10
    -0
      demofiles/out-of-bounds-access.c
  10. +15
    -0
      demofiles/pointer-compare.c
  11. +11
    -0
      demofiles/pointer-increment.c
  12. +10
    -0
      demofiles/pointer-out-of-bounds.c
  13. +9
    -0
      demofiles/segmentation-fault.c
  14. +15
    -0
      demofiles/use-after-free.c
  15. +1826
    -0
      main.leg
  16. +1
    -0
      stdio.h
  17. +0
    -0
      stdlib.h
  18. +0
    -0
      string.h
  19. +11
    -0
      test.txt

+ 29
- 0
Makefile Ver arquivo

@ -0,0 +1,29 @@
CFLAGS = -g
CPPFLAGS = -I/opt/local/include
LDFLAGS = -L/opt/local/lib
LDLIBS = -lgc
all : main
%.c : %.leg
leg -o $@ $<
% : %.c
cc $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $<
test : main
./main -xvv test.txt
demo : main
for i in demofiles/*.c; do echo $$i; ./main -x < $$i; done
demov : main
for i in demofiles/*.c; do echo $$i; ./main -x -vv < $$i; done
spotless : clean
rm -rf *~ *.dSYM
clean : .FORCE
rm -f main
.FORCE :

+ 0
- 0
assert.h Ver arquivo


+ 14
- 0
demofiles/Makefile Ver arquivo

@ -0,0 +1,14 @@
SRC = $(wildcard *.c)
EXE = $(SRC:.c=)
CFLAGS = -Wno-return-stack-address
all : $(EXE)
spotless : clean
rm -f *~
clean : .FORCE
rm -rf $(EXE) *.dSYM
.FORCE :

+ 18
- 0
demofiles/dangling-pointer.c Ver arquivo

@ -0,0 +1,18 @@
// dangling-pointer
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
int *alloc() {
int i;
return &i;
}
int main() {
int *ptr = alloc();
assert(ptr);
*ptr = 42;
printf("%d\n", *ptr);
return 0;
}

+ 11
- 0
demofiles/invalid-pointer.c Ver arquivo

@ -0,0 +1,11 @@
// invalid-pointer
#include <stdio.h>
int main() {
int *ptr = (int *)(intptr_t)0xDeadD0d0;
printf("%p\n",ptr);
*ptr = 42; // illegal memory access
printf("%d\n", *ptr);
return 0;
}

+ 14
- 0
demofiles/memory-leak.c Ver arquivo

@ -0,0 +1,14 @@
// memory-leak
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
int main() {
for (int i = 0; i < 10; ++i) {
int *ptr = malloc(sizeof(*ptr));
assert(ptr);
*ptr = i;
}
return 0;
}

+ 13
- 0
demofiles/multiple-free.c Ver arquivo

@ -0,0 +1,13 @@
// multiple-free
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
int main() {
int *ptr = malloc(sizeof(*ptr));
assert(ptr);
free(ptr);
free(ptr);
return 0;
}

+ 9
- 0
demofiles/null-pointer.c Ver arquivo

@ -0,0 +1,9 @@
// null-pointer
#include <stdio.h>
int main() {
char *ptr = NULL;
printf("%s\n", ptr);
return 0;
}

+ 10
- 0
demofiles/out-of-bounds-access.c Ver arquivo

@ -0,0 +1,10 @@
// out-of-bounds-access
#include <stdio.h>
int main() {
int array[5] = { 0, 1, 2, 3, 4 }, i = 4;
printf("%d\n", array[i++]);
printf("%d\n", array[i++]); // out of bounds
return 0;
}

+ 15
- 0
demofiles/pointer-compare.c Ver arquivo

@ -0,0 +1,15 @@
// pointer-compare
#include <stdlib.h>
#include <stdio.h>
int main() {
int array[5] = {0, 1, 2, 3, 4};
int brray[5] = {0, 1, 2, 3, 4};
int *p = array + 2;
int *q = array + 4;
int *r = brray + 4;
if (p > q) abort();
if (p > r) abort(); // illegal comparison
return 0;
}

+ 11
- 0
demofiles/pointer-increment.c Ver arquivo

@ -0,0 +1,11 @@
// pointer-increment
#include <stdio.h>
int main() {
int array[5] = {0, 1, 2, 3, 4};
int *ptr = array + 4;
++ptr;
++ptr; // out of bounds
return 0;
}

+ 10
- 0
demofiles/pointer-out-of-bounds.c Ver arquivo

@ -0,0 +1,10 @@
// pointer-out-of-bounds
#include <stdio.h>
int main() {
int array[5] = {0, 1, 2, 3, 4};
int *ptr = &array[5];
*ptr = 42;
return 0;
}

+ 9
- 0
demofiles/segmentation-fault.c Ver arquivo

@ -0,0 +1,9 @@
// segmentation-fault
#include <stdio.h>
int main() {
int *ptr = NULL;
*ptr = 42;
return 0;
}

+ 15
- 0
demofiles/use-after-free.c Ver arquivo

@ -0,0 +1,15 @@
// use-after-free
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
int main() {
int *ptr = malloc(sizeof(*ptr));
assert(ptr);
*ptr = 42;
free(ptr);
printf("%d\n", *ptr); // use after free
*ptr = 43; // use after free
return 0;
}

+ 1826
- 0
main.leg
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


+ 1
- 0
stdio.h Ver arquivo

@ -0,0 +1 @@
// here is stdio

+ 0
- 0
stdlib.h Ver arquivo


+ 0
- 0
string.h Ver arquivo


+ 11
- 0
test.txt Ver arquivo

@ -0,0 +1,11 @@
// -*- C -*-
#include <stdio.h>
#include "myfile.c"
int main()
{
printf("hello, world\n");
return 0;
}

Carregando…
Cancelar
Salvar