Signed-off-by: Mike Leach mike.leach@linaro.org --- decoder/tests/source/mem_buff_demo.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/decoder/tests/source/mem_buff_demo.cpp b/decoder/tests/source/mem_buff_demo.cpp index cacc227..052870f 100644 --- a/decoder/tests/source/mem_buff_demo.cpp +++ b/decoder/tests/source/mem_buff_demo.cpp @@ -126,6 +126,7 @@ static int initDataBuffers() FILE *fp; std::string filename; long size; + size_t bytes_read;
/* the file names to create the data buffers */ #ifdef _WIN32 @@ -158,8 +159,10 @@ static int initDataBuffers() return OCSD_ERR_MEM; } rewind(fp); - fread(input_trace_data, 1, input_trace_data_size, fp); + bytes_read = fread(input_trace_data, 1, input_trace_data_size, fp); fclose(fp); + if (bytes_read < (size_t)input_trace_data_size) + return OCSD_ERR_FILE_ERROR;
/* load up a memory image */ filename = default_base_snapshot_path; @@ -178,8 +181,10 @@ static int initDataBuffers() return OCSD_ERR_MEM; } rewind(fp); - fread(program_image_buffer, 1, program_image_size, fp); + bytes_read = fread(program_image_buffer, 1, program_image_size, fp); fclose(fp); + if (bytes_read < (size_t)program_image_size) + return OCSD_ERR_FILE_ERROR; program_image_address = mem_dump_address; return OCSD_OK; }