0

Good afternoon all!

Do not understand why program is not passing check50. All images are creating, Valgrind is passing successfully.

I have checked also code by gdb. Was created a special file which contains only jpeg headers. GDB was passed successfully , was reached place RETURN 0.

Could somebody help to understand why check50 is failing?

145     fclose(dump);
(gdb) 
146     return 0;
(gdb) 
__libc_start_main (main=0x8048690 <main>, argc=2, ubp_av=0xbffff0a4, 
    init=0x8048be0 <__libc_csu_init>, fini=0x8048c50 <__libc_csu_fini>, 
    rtld_fini=0x4cf5d8e0 <_dl_fini>, stack_end=0xbffff09c) at libc-start.c:292

292   exit (result);
(gdb) 
[Inferior 1 (process 16405) exited normally]

pseudo-code:

 do
 {
   fread(&st,,, inptr);

   if ( if jpeg)

       { 
          fseek(inptr, -read_size, SEEK_CUR);
          break;
       } 

 } while (1 == 1);


 while   (c == 512) 
  {
    c = fread(&st, , , inptr);

     if (if jpeg)
      {
        sprintf(new_jpg, "%.3d.jpg", k);
        FILE* outfile = fopen(new_jpg, "w");
        if (outfile == NULL)
         {
           return 5;
         }

        fwrite(&st, , ,outfile);
        k = k + 1;

          while  (c == 512)
            { 
             b = fread(&st,, , inptr);

            if  (if jpeg)
              {
               fseek(inptr,  -read_size, SEEK_CUR);  
               fclose(outfile);   
               break;
              }
            else if (b != 512)
              {
               fclose(outfile);
               c = b;
               break;
              }
              //else
              fwrite(&st, , ,outfile);

            }  
      }
    if (c != 512)
     break;
  }
fclose(inptr);
return 0;

Result from VALGRIND

jharvard@appliance (~/Dropbox/pset4/jpg): valgrind ./recover card.raw 
==6146== Memcheck, a memory error detector
==6146== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==6146== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==6146== Command: ./recover card.raw
==6146== 
==6146== 
==6146== HEAP SUMMARY:
==6146==     in use at exit: 0 bytes in 0 blocks
==6146==   total heap usage: 17 allocs, 17 frees, 5,984 bytes allocated
==6146== 
==6146== All heap blocks were freed -- no leaks are possible
==6146== 
==6146== For counts of detected and suppressed errors, rerun with: -v
==6146== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

All images are creating and they can be viewed:

Results Result from check50:

https://sandbox.cs50.net/checks/8f6fa0129436458ab1122b49f0b94cba

Thanks in advance for help!

1

The problem was very funny =) I understood incorrect description : "hardcode file name"

Before that i just forced user to type file name card.raw, i thought this was requirement by:

For simplicity, you should hard-code "card.raw" in your program; your program need not accept any command-line arguments.

Just haven't read it carefully ^_^

0

Is your new_jpg a char[8] array? Could be similar issue as this person : Recover creates the pictures, able to view them, but listed as jpg? in ls and check50 fails

2
  • Yes, new_jpeg is a char[8], otherwise valgrind should detect a error. – LeVl Mar 28 '15 at 20:38
  • somebody can help with this question ? :-) – LeVl Apr 15 '15 at 22:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .