# HG changeset patch # User Sadrul Habib Chowdhury # Date 1192190795 0 # Node ID 70082d0db571f241265658a8412cc2014b6d913f # Parent 8de7c44fd5773bff5f8f9f570d874ac208214388 Pay attention to the return value of fread. I don't think not doing this would cause any problems. But try telling that to the compiler! diff -r 8de7c44fd577 -r 70082d0db571 libpurple/plugins/log_reader.c --- a/libpurple/plugins/log_reader.c Fri Oct 12 11:51:13 2007 +0000 +++ b/libpurple/plugins/log_reader.c Fri Oct 12 12:06:35 2007 +0000 @@ -103,9 +103,10 @@ } else { char *filename = g_build_filename(path, file, NULL); FILE *handle = g_fopen(filename, "rb"); - char *contents; + char contents[57]; /* XXX: This is really inflexible. */ char *contents2; struct adium_logger_data *data; + size_t rd; PurpleLog *log; if (!handle) { @@ -113,11 +114,9 @@ continue; } - /* XXX: This is really inflexible. */ - contents = g_malloc(57); - fread(contents, 56, 1, handle); + rd = fread(contents, 56, 1, handle) == 0; fclose(handle); - contents[56] = '\0'; + contents[rd] = '\0'; /* XXX: This is fairly inflexible. */ contents2 = contents; @@ -135,11 +134,9 @@ purple_debug_error("Adium log parse", "Contents timestamp parsing error\n"); - g_free(contents); g_free(filename); continue; } - g_free(contents); data = g_new0(struct adium_logger_data, 1); data->path = filename; @@ -168,21 +165,20 @@ } else { char *filename = g_build_filename(path, file, NULL); FILE *handle = g_fopen(filename, "rb"); - char *contents; + char contents[14]; /* XXX: This is really inflexible. */ char *contents2; struct adium_logger_data *data; PurpleLog *log; + size_t rd; if (!handle) { g_free(filename); continue; } - /* XXX: This is really inflexible. */ - contents = g_malloc(14); - fread(contents, 13, 1, handle); + rd = fread(contents, 13, 1, handle); fclose(handle); - contents[13] = '\0'; + contents[rd] = '\0'; contents2 = contents; while (*contents2 && *contents2 != '(') @@ -195,13 +191,10 @@ purple_debug_error("Adium log parse", "Contents timestamp parsing error\n"); - g_free(contents); g_free(filename); continue; } - g_free(contents); - tm.tm_year -= 1900; tm.tm_mon -= 1; @@ -1446,7 +1439,7 @@ file = g_fopen(data->path, "rb"); fseek(file, data->offset, SEEK_SET); - fread(read, data->length, 1, file); + data->length = fread(read, data->length, 1, file); fclose(file); if (read[data->length-1] == '\n') { @@ -1945,7 +1938,7 @@ contents = g_malloc(data->length + 2); fseek(file, data->offset, SEEK_SET); - fread(contents, data->length, 1, file); + data->length = fread(contents, data->length, 1, file); fclose(file); contents[data->length] = '\n'; @@ -2338,7 +2331,7 @@ g_return_val_if_fail(file != NULL, g_strdup("")); fseek(file, data->offset, SEEK_SET); - fread(contents, data->length, 1, file); + data->length = fread(contents, data->length, 1, file); fclose(file); contents[data->length] = '\n';