diff options
author | nxf48293 <priyanka.rajput@nxp.com> | 2019-06-10 10:36:21 +0530 |
---|---|---|
committer | nxf24591 <nanjesh.s_1@nxp.com> | 2019-07-01 20:26:26 +0530 |
commit | 20359f8b9872a8f85304dab190b1bee6f5f56969 (patch) | |
tree | 3c7ae084380df1b3b5a7578e3221a1a5b0866be5 /halimpl/utils/phNxpConfig.cpp | |
parent | e1cee2c094ca0b5086a006782a0b9416bff2e0dd (diff) |
Fixed coverity warnings
Warnings Fixed: CHECKED_RETURN
Diffstat (limited to 'halimpl/utils/phNxpConfig.cpp')
-rwxr-xr-x | halimpl/utils/phNxpConfig.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/halimpl/utils/phNxpConfig.cpp b/halimpl/utils/phNxpConfig.cpp index 77587b9..98690c1 100755 --- a/halimpl/utils/phNxpConfig.cpp +++ b/halimpl/utils/phNxpConfig.cpp @@ -85,28 +85,27 @@ namespace { size_t readConfigFile(const char* fileName, uint8_t** p_data) { FILE* fd = fopen(fileName, "rb"); - uint8_t *buffer = NULL; - size_t read = 0; if (fd == nullptr) return 0; - fseek(fd, 0L, SEEK_END); const size_t file_size = ftell(fd); rewind(fd); - - if (file_size > 0) { - buffer = new uint8_t[file_size]; - read = fread(buffer, file_size, 1, fd); - } else { - ALOGE("%s Invalid file size file_size = %zu\n", __func__, file_size); + if((long)file_size < 0){ + ALOGE("%s Invalid file size file_size = %zu\n",__func__,file_size); + fclose(fd); + return 0; } + uint8_t* buffer = new uint8_t[file_size]; + if (!buffer) { + ALOGE("%s memory allocation failed \n",__func__); + return 0; + } + size_t read = fread(buffer, file_size, 1, fd); fclose(fd); - if (read == 1) { *p_data = buffer; return file_size; } - if (buffer) - delete[] buffer; + delete[] buffer; return 0; } |