Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
***“./recover”中出错:free():下一个大小无效(正常)_C - Fatal编程技术网

***“./recover”中出错:free():下一个大小无效(正常)

***“./recover”中出错:free():下一个大小无效(正常),c,C,这些代码不起作用! 它必须读取512字节块,直到文件结束 瓦尔格林说一切都好! 分配的数据在最后释放 *“./recover”中出错:空闲:无效下一个大小正常:0x09e89170* 中止堆芯转储 #include <stdio.h> #include <stdlib.h> #include <stdint.h> #define B_SIZE 512 char* getTitle (int c); int main(int argc, char* ar

这些代码不起作用! 它必须读取512字节块,直到文件结束

瓦尔格林说一切都好! 分配的数据在最后释放 *“./recover”中出错:空闲:无效下一个大小正常:0x09e89170* 中止堆芯转储

#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;
}
将B_SIZE*128512*128=64k字节读入一个只有512字节的缓冲区。这将写入超出分配内存的范围,并导致未定义的行为

如果您希望一次只读取512字节,则执行以下操作:

fread(data, 1, B_SIZE, file);
可能重复的