diff options
| author | Dani Martin <[email protected]> | 2020-03-30 13:51:36 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-03-30 13:51:36 +0200 |
| commit | 62cdb2299bd2a9f96f854b06fee5e4429a5f9e25 (patch) | |
| tree | b26b3404c3d7ab81ade9978186e28081914eb71e /src/utils.c | |
| parent | 9b66883e0b1278958420a7e6259402db15f3ac18 (diff) | |
| download | raylib-62cdb2299bd2a9f96f854b06fee5e4429a5f9e25.tar.gz raylib-62cdb2299bd2a9f96f854b06fee5e4429a5f9e25.zip | |
[cppcheck] Improvements in SaveStorageValue() in core.c (#1160)
* [cppcheck] Improvements in SaveStorageValue() in core.c
in file core.c cppcheck shows errors only in function SaveStorageValue():
* Common realloc mistake: 'fileData' nulled but not freed upon failure
* Memory pointed to by 'fileData' is freed twice.
Validation:
* Tested examples/core/core_storage_values.c
* Launched Unit Test for this function
* Rerun CPPCHECK afer fix
* [cppcheck] Change functions header to accept only positive position in files
Changes:
* Functions SaveStorageValue(), LoadStorageValue() (core.c)
* Functions LoadFileData(), SaveFileData() (utils.c)
* Headers in raylib.h
Validation:
* Tested examples/core/core_storage_values.c
* Launched Unit Test for these functions
* Rerun CPPCHECK afer fix
Diffstat (limited to 'src/utils.c')
| -rw-r--r-- | src/utils.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/utils.c b/src/utils.c index 1fe9e299..5ba8b007 100644 --- a/src/utils.c +++ b/src/utils.c @@ -165,7 +165,7 @@ void TraceLog(int logType, const char *text, ...) } // Load data from file into a buffer -unsigned char *LoadFileData(const char *fileName, int *bytesRead) +unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead) { unsigned char *data = NULL; *bytesRead = 0; @@ -187,7 +187,7 @@ unsigned char *LoadFileData(const char *fileName, int *bytesRead) data = (unsigned char *)RL_MALLOC(sizeof(unsigned char)*size); // NOTE: fread() returns number of read elements instead of bytes, so we read [1 byte, size elements] - int count = fread(data, sizeof(unsigned char), size, file); + unsigned int count = fread(data, sizeof(unsigned char), size, file); *bytesRead = count; if (count != size) TRACELOG(LOG_WARNING, "FILEIO: [%s] File partially loaded", fileName); @@ -205,7 +205,7 @@ unsigned char *LoadFileData(const char *fileName, int *bytesRead) } // Save data to file from buffer -void SaveFileData(const char *fileName, void *data, int bytesToWrite) +void SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite) { if (fileName != NULL) { @@ -213,7 +213,7 @@ void SaveFileData(const char *fileName, void *data, int bytesToWrite) if (file != NULL) { - int count = fwrite(data, sizeof(unsigned char), bytesToWrite, file); + unsigned int count = fwrite(data, sizeof(unsigned char), bytesToWrite, file); if (count == 0) TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to write file", fileName); else if (count != bytesToWrite) TRACELOG(LOG_WARNING, "FILEIO: [%s] File partially written", fileName); |
