Skip to content

Commit

Permalink
Incidentally, fixing intermittent error on srlp and btctx unit tests
Browse files Browse the repository at this point in the history
This error was happening intermittently in my local, and now has
happened in the CI as well. Turns out ferror was not working well
with fclose, since it would mistakenly report an error while
errno is set to 0.
  • Loading branch information
italo-sampaio committed Nov 26, 2024
1 parent 93d6f11 commit e54f33f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions firmware/src/powhsm/test/btctx/test_btctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ int read_hex_file(const char* file_name, unsigned char** buffer, size_t* len) {
fread(tmp, 2, 1, f);
read_hex(tmp, 2, *buffer + off);
}
fclose(f);

if (ferror(f)) {
return -1;
}

if (fclose(f)) {
return -1;
}

return 0;
}

Expand Down
5 changes: 4 additions & 1 deletion firmware/src/powhsm/test/srlp/test_srlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,15 @@ int read_block_file(const char* file_name, char** buffer, size_t* len) {

*buffer = malloc(*len);
fread(*buffer, *len, 1, f);
fclose(f);

if (ferror(f)) {
return -1;
}

if (fclose(f)) {
return -1;
}

return 0;
}

Expand Down

0 comments on commit e54f33f

Please sign in to comment.