This commit is contained in:
Sebastian Ramacher 2019-11-30 11:51:27 +01:00
parent 43144b23e8
commit 5a5ee06407

View file

@ -179,12 +179,10 @@ guess_type_glib(const char* path)
return NULL; return NULL;
} }
const int fd = fileno(f);
guchar* content = NULL; guchar* content = NULL;
size_t length = 0u; size_t length = 0;
ssize_t bytes_read = -1; while (uncertain == TRUE && length < GT_MAX_READ) {
while (uncertain == TRUE && length < GT_MAX_READ && bytes_read != 0) { g_free(content_type);
g_free((void*)content_type);
content_type = NULL; content_type = NULL;
guchar* temp_content = g_try_realloc(content, length + BUFSIZ); guchar* temp_content = g_try_realloc(content, length + BUFSIZ);
@ -193,8 +191,8 @@ guess_type_glib(const char* path)
} }
content = temp_content; content = temp_content;
bytes_read = read(fd, content + length, BUFSIZ); size_t bytes_read = fread(content + length, 1, BUFSIZ, f);
if (bytes_read == -1) { if (bytes_read == 0) {
break; break;
} }
@ -209,7 +207,7 @@ guess_type_glib(const char* path)
return content_type; return content_type;
} }
g_free((void*)content_type); g_free(content_type);
return NULL; return NULL;
} }