Skip to content

Commit

Permalink
Change getc return type from char to int32_t
Browse files Browse the repository at this point in the history
The return type of `getc(3)` is a signed integer,
with negative values indicating an error. The changed
line stored the return value in an *unsigned* integer,
then tested it against a negative error constant, so
the error condition would never be detected. This
also results in a warning on GCC 10.

Further information:
- [`getc(3)`](https://man7.org/linux/man-pages/man3/fgetc.3.html)
- [C FAQ question 12.1](http://c-faq.com/stdio/getcharc.html)
  • Loading branch information
overhacked committed Jan 27, 2022
1 parent dc27bab commit 7ed7014
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion software/writeentropy.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static uint32_t readNumberFromFile(char *fileName) {
exit(1);
}
uint32_t value = 0u;
char c;
int32_t c;
while( (c = getc(file)) != EOF
&& '0' <= c && c <= '9' ) {
value *= 10;
Expand Down

0 comments on commit 7ed7014

Please sign in to comment.