eswincomputing / Esbd-77serial-nsign

GNU General Public License v2.0
0 stars 2 forks source link

Missing checks for return values of file functions #2

Open xypron opened 2 months ago

xypron commented 2 months ago

Building results in warnings

src/esw_build_signature.cpp:913:14: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  913 |         fread(buffer_bin, 1, NUMBER_OF_ONE_LINE, src_file);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/esw_build_signature.cpp:949:14: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  949 |         fread(buffer_bin, 1, src_file_remainder, src_file);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/esw_build_signature.cpp: In function ‘int create_chief_sign_file()’:
src/esw_build_signature.cpp:1159:18: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 1159 |             fread(&tmp, 1, 1, fr);
      |             ~~~~~^~~~~~~~~~~~~~~~

The return values of fseek, fread, fwrite should be checked. Failures should result in exiting the program.

NingYu00 commented 2 months ago

We submitted code to solve the above problem: commit d1d48f48660a0dae9f6978ef99bbbcaf2944f3bb