Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential char overflow bug #515

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion extern/test_bmi_c/src/bmi_test_bmi_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,11 @@ int read_file_line_counts(const char* file_name, int* line_count, int* max_line_
return -1;
}
int seen_non_whitespace = 0;
char c;
int c; //EOF is a negative constant...and char may be either signed OR unsigned
//depending on the compiler, system, achitectured, ect. So there are cases
//where this loop could go infinite comparing EOF to unsigned char
//the return of fgetc is int, and should be stored as such!
//https://stackoverflow.com/questions/35356322/difference-between-int-and-char-in-getchar-fgetc-and-putchar-fputc
for (c = fgetc(fp); c != EOF; c = fgetc(fp)) {
// keep track if this line has seen any char other than space or tab
if (c != ' ' && c != '\t' && c != '\n')
Expand Down
6 changes: 5 additions & 1 deletion extern/test_bmi_cpp/src/test_bmi_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@ void TestBmiCpp::read_file_line_counts(std::string file_name, int* line_count, i
throw std::runtime_error("Configuration file does not exist." SOURCE_LOC);
}
int seen_non_whitespace = 0;
char c;
int c; //EOF is a negative constant...and char may be either signed OR unsigned
//depending on the compiler, system, achitectured, ect. So there are cases
//where this loop could go infinite comparing EOF to unsigned char
//the return of fgetc is int, and should be stored as such!
//https://stackoverflow.com/questions/35356322/difference-between-int-and-char-in-getchar-fgetc-and-putchar-fputc
for (c = fgetc(fp); c != EOF; c = fgetc(fp)) {
// keep track if this line has seen any char other than space or tab
if (c != ' ' && c != '\t' && c != '\n')
Expand Down