h5, g3df.c: fix wrong error fread() checks.

commit 4b63afa8 by jwrdegoede added fread() checks like:

 if(fread(buf,size,nelem,fp) != size*nelem) error();

however the check must be against nelem alone, and _not_
the total bytes.
This commit is contained in:
sezero
2018-08-22 02:24:24 +03:00
parent c30be75227
commit 66386d5ac4
4 changed files with 7 additions and 14 deletions

View File

@@ -617,8 +617,7 @@ Read8Bit(FxU8 *data, FILE *image_file,
width = _grMipMapHostWH[aspect_ratio][lod][0];
height = _grMipMapHostWH[aspect_ratio][lod][1];
if (fread(data, sizeof(char), width*height, image_file) !=
(sizeof(char)*width*height))
if (fread(data, 1, width*height, image_file) != (width*height))
return FXFALSE;
data += width*height;
}

View File

@@ -622,8 +622,7 @@ Read8Bit(FxU8 *data, FILE *image_file,
width = _grMipMapHostWH[aspect_ratio][lod][0];
height = _grMipMapHostWH[aspect_ratio][lod][1];
if (fread(data, sizeof(char), width*height, image_file) !=
(sizeof(char)*width*height))
if (fread(data, 1, width*height, image_file) != (width*height))
return FXFALSE;
data += width*height;
}

View File

@@ -969,8 +969,7 @@ Read4Bit(FxU8 *data, FILE *image_file, int small_lod, int large_lod,
read 16 bytes at a time. */
thisMipMapByteCount = (width * height) >> 5;
if (fread(data, 16, thisMipMapByteCount, image_file) !=
(16*thisMipMapByteCount))
if (fread(data, 16, thisMipMapByteCount, image_file) != thisMipMapByteCount)
return FXFALSE;
data += (16 * thisMipMapByteCount);
}
@@ -1001,8 +1000,7 @@ ReadDXT4Bit(FxU8 *data, FILE *image_file, int small_lod, int large_lod,
/* Divide the WxH by 16 to read 8 bytes at a time. */
thisMipMapByteCount = (width * height) >> 4;
if (fread(data, 8, thisMipMapByteCount, image_file) !=
(8 * thisMipMapByteCount))
if (fread(data, 8, thisMipMapByteCount, image_file) != thisMipMapByteCount)
return FXFALSE;
data += (8 * thisMipMapByteCount);
}
@@ -1033,8 +1031,7 @@ ReadDXT8Bit(FxU8 *data, FILE *image_file,
read 16 bytes at a time. */
thisMipMapByteCount = (width * height) >> 4;
if (fread(data, 16, thisMipMapByteCount, image_file) !=
(16 * thisMipMapByteCount))
if (fread(data, 16, thisMipMapByteCount, image_file) != thisMipMapByteCount)
return FXFALSE;
data += (16 * thisMipMapByteCount);
}
@@ -1061,8 +1058,7 @@ Read8Bit(FxU8 *data, FILE *image_file,
thisMipMapByteCount = width * height;
if (fread(data, sizeof(char), thisMipMapByteCount, image_file) !=
(sizeof(char) * thisMipMapByteCount))
if (fread(data, 1, thisMipMapByteCount, image_file) != thisMipMapByteCount)
return FXFALSE;
data += thisMipMapByteCount;
}

View File

@@ -515,8 +515,7 @@ Read8Bit(FxU8 *data, FILE *image_file,
width = _grMipMapHostWH[aspect_ratio][lod][0];
height = _grMipMapHostWH[aspect_ratio][lod][1];
if (fread(data, sizeof(char), width*height, image_file) !=
(sizeof(char)*width*height))
if (fread(data, 1, width*height, image_file) != (width*height))
return FXFALSE;
data += width*height;
}