Dieser Code funktioniert nicht! Es muss 512-Byte-Blöcke bis zum Ende der Datei lesen!*** Fehler in `./recover ': free(): ungültig nächste Größe (normal)
- Valgrind sagte, dass alles ok!
- zugeordneten Daten am Ende
* Fehler in `./recover 'sind befreit: free(): nächste Größe (normal) ungültig: 0x09e89170 * Aborted (core dumped)
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define B_SIZE 512
char* getTitle (int c);
int main(int argc, char* argv[])
{
// TODO
long size;
uint32_t *data;
// open file
FILE* file = fopen("card.raw", "r");
if (!file) {
fprintf(stderr, "Unable to open/create file\n");
return 1;
}
fseek(file, 0, SEEK_END);
size = ftell(file);
fseek(file, 0, SEEK_SET);
if (!(data = malloc(512))) {
fprintf(stderr, "Failed to allocate memory\n");
return 1;
}
while(true) // until end
{
// read 512 block
if (ftell(file) >= size-2048)
{
printf("STOP\n");
break;
}
fread(data, B_SIZE, 128, file);
printf("%ld, (%li)\n", ftell(file), size);
}
// close all files
free(data);
fclose(file);
return 0;
}