Merge pull request #347 from thrasymache/overflow
print_file_contents: allocate enough to include \0
This commit is contained in:
commit
bd7de0c8ff
@ -23,7 +23,7 @@ static void *scalloc(size_t size) {
|
||||
void print_file_contents(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format, const char *format_bad, const int max_chars) {
|
||||
const char *walk = format;
|
||||
char *outwalk = buffer;
|
||||
char *buf = scalloc(max_chars * sizeof(char));
|
||||
char *buf = scalloc(max_chars * sizeof(char) + 1);
|
||||
|
||||
int n = -1;
|
||||
int fd = open(path, O_RDONLY);
|
||||
|
@ -1 +1 @@
|
||||
contents | NONEXISTANT - 2: No such file or directory
|
||||
contents | con | NONEXISTANT - 2: No such file or directory
|
||||
|
@ -3,12 +3,18 @@ general {
|
||||
}
|
||||
|
||||
order += "read_file EXISTING"
|
||||
order += "read_file TRUNCATED"
|
||||
order += "read_file NONEXISTANT"
|
||||
|
||||
read_file EXISTING {
|
||||
path = "testcases/025-file-contents/short.txt"
|
||||
}
|
||||
|
||||
read_file TRUNCATED {
|
||||
path = "testcases/025-file-contents/short.txt"
|
||||
max_characters = 3
|
||||
}
|
||||
|
||||
read_file NONEXISTANT {
|
||||
path = "testcases/025-file-contents/nonexistant"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user