Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. ; // Machine code
  2. 35 ; number of lines
  3. 12 ; [ 0 ] MOV R0 5
  4. 0 ; [ 1 ]
  5. ...
  6.  
  7. int main(){
  8. int size = 0;
  9. FILE *in;
  10. char filename[128] = "";
  11.  
  12. printf("Enter the name of the file.n");
  13. scanf("%s", filename);
  14. in = fopen(filename, "r");
  15. size = findSize(filename);
  16. printf("size: %dn", size);
  17.  
  18. return 0;
  19. }
  20.  
  21. int findSize(FILE *in){
  22. char *textLine = NULL, *line_buf = NULL;
  23. size_t line_in_buf_size = 0;
  24. int number = 0, found = 0;
  25.  
  26. while (getline(&line_buf, &line_in_buf_size, in) >= 0 && found == 0){ //keeps reading lines untile reaching EOF or finding the first valid number
  27. printf("analyzing %sn", line_buf);
  28. textLine = strtok(line_buf, ";"); //only considers characters before ";"
  29. if ((*textLine >= '0') && (*textLine <= '9')) { //if the found characters are numbers, I'll convert them to integers and exit the loop
  30. number = atoi(textLine);
  31. found = 1;
  32. }
  33. }
  34.  
  35. return number;
  36. }
  37.  
  38. Enter the name of the file.
  39. factorial.txt
  40. =================================================================
  41. ==1480==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x7ffee8a649c0 in thread T0
  42. #0 0x10720c7f0 in wrap_realloc (libasan.5.dylib:x86_64+0x6c7f0)
  43. #1 0x7fff652faab1 in sappend (libsystem_c.dylib:x86_64+0x3dab1)
  44. #2 0x7fff652fa99f in getdelim (libsystem_c.dylib:x86_64+0x3d99f)
  45. #3 0x10719c19a in findSize (a.out:x86_64+0x10000119a)
  46. #4 0x7478742e6b (<unknown module>)
  47.  
  48. Address 0x7ffee8a649c0 is located in stack of thread T0 at offset 112 in frame
  49. #0 0x10719c096 in findSize (a.out:x86_64+0x100001096)
  50.  
  51. This frame has 2 object(s):
  52. [32, 40) 'line_in'
  53. [96, 104) 'line_in_buf_size' <== Memory access at offset 112 overflows this variable
  54. HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
  55. (longjmp and C++ exceptions *are* supported)
  56. SUMMARY: AddressSanitizer: bad-free (libasan.5.dylib:x86_64+0x6c7f0) in wrap_realloc
  57. ==1480==ABORTING
  58. Abort trap: 6
  59.  
  60. int findSize(const char *filename)
  61.  
  62. size = findSize("factorial.txt");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement