Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 1.24 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Invalid read of size 1 in strstr() using valgrind
  2. ==7001== Invalid read of size 1
  3. ==7001==    at 0x402E21B: strstr (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
  4. ==7001==    by 0x8049742: replace_in_file (functions.c:191)
  5. ==7001==    by 0x8049C55: parse_dir (functions.c:295)
  6. ==7001==    by 0x8049059: main (main.c:214)
  7. ==7001==  Address 0x42018c3 is 0 bytes after a block of size 3 alloc'd
  8. ==7001==    at 0x402B018: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
  9. ==7001==    by 0x80496EC: replace_in_file (functions.c:183)
  10. ==7001==    by 0x8049C55: parse_dir (functions.c:295)
  11. ==7001==    by 0x8049059: main (main.c:214)
  12.        
  13. long int replace_in_file(char **sets, FILE *file, char *path, const char *mode){
  14.     long int n = 0, size = 0, len, remaining_len;
  15.  
  16.     char *buffer,
  17.          *found,
  18.          *before,
  19.          *after;
  20.  
  21.     size = file_size(file);
  22.     if(-1 != size){
  23.  
  24.         buffer = malloc(size * sizeof(char));
  25.  
  26.         rewind(file);
  27.         fread(buffer, 1, size, file);
  28.  
  29.         int i=0;
  30.         do{
  31.             do{
  32.                 found = strstr(buffer, sets[i]); // LINE 191
  33.                 if(NULL != found && '' != sets[i][0]){
  34.  
  35. //rest of code...
  36.        
  37. buffer = malloc((size + 1) * sizeof(char));
  38. memset(buffer, '', size + 1);