diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lodepng.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lodepng.cpp b/src/lodepng.cpp index 3bf1d46..46011a8 100644 --- a/src/lodepng.cpp +++ b/src/lodepng.cpp @@ -4125,9 +4125,12 @@ unsigned LodePNG_loadFile(unsigned char** out, size_t* outsize, const char* file rewind(file); /*read contents of the file into the vector*/ - *outsize = 0; - *out = (unsigned char*)malloc((size_t)size); - if(size && (*out)) (*outsize) = fread(*out, 1, (size_t)size, file); + if (size>0) + { + *outsize = 0; + *out = (unsigned char*)malloc((size_t)size); + if(size && (*out)) (*outsize) = fread(*out, 1, (size_t)size, file); + } fclose(file); if(!(*out) && size) return 80; /*the above malloc failed*/ |