fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <cstdlib>
  4.  
  5. int g_buf[4000];
  6.  
  7. void test1() {
  8. for (int i=0;i<=4096;i++) {
  9. g_buf[i] = i;
  10. }
  11. std::cout << " test1 " << g_buf[4096];
  12. }
  13.  
  14. void test2() {
  15. int* buf = new int[4000];
  16. for (int i=0;i<=4096;i++) {
  17. buf[i] = i;
  18. }
  19. std::cout << " test2 " << buf[4096];
  20. }
  21.  
  22. void test3() {
  23. int* buf = (int*)malloc(sizeof(int)*4000);
  24. for (int i=0;i<=4096;i++) {
  25. buf[i] = i;
  26. }
  27. std::cout << " test3 " << buf[4096];
  28. }
  29.  
  30. int main(int argc, char** argv) {
  31. test1();
  32. test2();
  33. test3();
  34. }
  35.  
  36.  
  37.  
  38.  
Runtime error #stdin #stdout #stderr 0s 3456KB
stdin
Standard input is empty
stdout
 test1 4096 test2 4096
stderr
prog: malloc.c:2369: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.