kids icon indicating copy to clipboard operation
kids copied to clipboard

fread错误使用

Open DongwenHuang opened this issue 10 years ago • 1 comments

int ret = fread(data, size, 1, file_); if (size == 0 || ret == 0) return false; if (ret == -1) {}

上面是你的filesystem.cc的代码,这段代码有错误,fread不会返回-1,当返回0的时候应该用feof,ferror来检测是什么原因导致返回的数目比1少,发生错误到关闭

引用下面这段话: RETURN VALUE fread and fwrite return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end-of-file is reached, the return value is a short item count (or zero).

   fread does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3)
   to determine which occurred.

DongwenHuang avatar Sep 01 '15 02:09 DongwenHuang

Thanks, can you create a pull request ?

lycplus avatar Dec 05 '16 14:12 lycplus