RicardasSim

segfault

Aug 10th, 2020 (edited)
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. /*
  2. Ubuntu 20.04.1 LTS (Focal Fossa)
  3. gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
  4.  
  5. gcc -std=c99 -Wall -Wextra -Wpedantic -Wshadow -O0 -DDEBUG -g main.c
  6.  
  7. Program received signal SIGSEGV, Segmentation fault.
  8. 0x0000555555555180 in main () at main.c:31
  9. 31  {
  10.  
  11.  
  12. gcc -std=c99 -Wall -Wextra -Wpedantic -Wshadow -O1 -DNDEBUG -g main.c OK
  13. gcc -std=c99 -Wall -Wextra -Wpedantic -Wshadow -O2 -DNDEBUG -g main.c OK
  14. gcc -std=c99 -Wall -Wextra -Wpedantic -Wshadow -O3 -DNDEBUG -g main.c OK
  15.  
  16. edit:
  17. possible stack overflow
  18.  
  19. solution:
  20. use malloc
  21.  
  22. https://pastebin.com/fYRAbMtb
  23. or https://pastebin.com/EuPakt7a
  24.  
  25. Tnx to ##C on Freenode !
  26. */
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <stdint.h>
  31. #include <stdbool.h>
  32.  
  33. #define TEST_A_MAX_SIZE 1000000
  34.  
  35. struct thread_test_a
  36. {
  37.     uint32_t variables[TEST_A_MAX_SIZE];
  38.     uint32_t test_count;
  39. };
  40.  
  41. int main()
  42. { // line 31
  43.  
  44.     struct thread_test_a thread_test_1;
  45.     struct thread_test_a thread_test_2;
  46.     struct thread_test_a thread_test_3;
  47.  
  48.     thread_test_1.test_count = TEST_A_MAX_SIZE;
  49.     thread_test_2.test_count = 10;
  50.     thread_test_3.test_count = 50;
  51.  
  52.     thread_test_1.variables[TEST_A_MAX_SIZE-1] = 1;
  53.     thread_test_2.variables[10] = 2;
  54.     thread_test_3.variables[50] = 3;
  55.  
  56.     printf( "%d\n", thread_test_1.variables[TEST_A_MAX_SIZE-1] );
  57.     printf( "%d\n", thread_test_2.variables[10] );
  58.     printf( "%d\n", thread_test_3.variables[50] );
  59.  
  60.     return 0;
  61. }
  62.  
Add Comment
Please, Sign In to add comment