Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; // Machine code
- 35 ; number of lines
- 12 ; [ 0 ] MOV R0 5
- 0 ; [ 1 ]
- ...
- int main(){
- int size = 0;
- FILE *in;
- char filename[128] = "";
- printf("Enter the name of the file.n");
- scanf("%s", filename);
- in = fopen(filename, "r");
- size = findSize(filename);
- printf("size: %dn", size);
- return 0;
- }
- int findSize(FILE *in){
- char *textLine = NULL, *line_buf = NULL;
- size_t line_in_buf_size = 0;
- int number = 0, found = 0;
- while (getline(&line_buf, &line_in_buf_size, in) >= 0 && found == 0){ //keeps reading lines untile reaching EOF or finding the first valid number
- printf("analyzing %sn", line_buf);
- textLine = strtok(line_buf, ";"); //only considers characters before ";"
- if ((*textLine >= '0') && (*textLine <= '9')) { //if the found characters are numbers, I'll convert them to integers and exit the loop
- number = atoi(textLine);
- found = 1;
- }
- }
- return number;
- }
- Enter the name of the file.
- factorial.txt
- =================================================================
- ==1480==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x7ffee8a649c0 in thread T0
- #0 0x10720c7f0 in wrap_realloc (libasan.5.dylib:x86_64+0x6c7f0)
- #1 0x7fff652faab1 in sappend (libsystem_c.dylib:x86_64+0x3dab1)
- #2 0x7fff652fa99f in getdelim (libsystem_c.dylib:x86_64+0x3d99f)
- #3 0x10719c19a in findSize (a.out:x86_64+0x10000119a)
- #4 0x7478742e6b (<unknown module>)
- Address 0x7ffee8a649c0 is located in stack of thread T0 at offset 112 in frame
- #0 0x10719c096 in findSize (a.out:x86_64+0x100001096)
- This frame has 2 object(s):
- [32, 40) 'line_in'
- [96, 104) 'line_in_buf_size' <== Memory access at offset 112 overflows this variable
- HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
- (longjmp and C++ exceptions *are* supported)
- SUMMARY: AddressSanitizer: bad-free (libasan.5.dylib:x86_64+0x6c7f0) in wrap_realloc
- ==1480==ABORTING
- Abort trap: 6
- int findSize(const char *filename)
- size = findSize("factorial.txt");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement