bugfix with invalid/corrupted index path

This commit is contained in:
simon 2019-11-11 20:49:38 -05:00
parent fc22e52eae
commit 6931d320a2

View File

@ -54,6 +54,12 @@ index_descriptor_t read_index_descriptor(char *path) {
struct stat info; struct stat info;
stat(path, &info); stat(path, &info);
int fd = open(path, O_RDONLY); int fd = open(path, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Invalid/corrupt index (Could not find descriptor)");
exit(1);
}
char *buf = malloc(info.st_size + 1); char *buf = malloc(info.st_size + 1);
read(fd, buf, info.st_size); read(fd, buf, info.st_size);
*(buf + info.st_size) = '\0'; *(buf + info.st_size) = '\0';