We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 44e97a4 commit b219873Copy full SHA for b219873
src/Util.cc
@@ -149,7 +149,8 @@ fileGetContents(FILE* f) {
149
char* output;
150
// Determine file size
151
fseek(f, 0, SEEK_END);
152
- size_t size = ftell(f);
+ // Need an extra byte for the null terminator.
153
+ size_t size = ftell(f) + 1;
154
155
// We don't want to allocate memory if the file size is zero, because it is
156
// undefined behavior to dereference such memory.
@@ -158,6 +159,7 @@ fileGetContents(FILE* f) {
158
159
output[0] = '\0';
160
} else {
161
output = new char[size];
162
+ output[size - 1] = '\0';
163
rewind(f);
164
fread(output, sizeof(char), size, f);
165
}
0 commit comments