From 176dbf53fc8fde316e133afcda2892973ea38cc7 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 17 Jan 2010 23:12:55 +0000 Subject: [PATCH] * Fixed another fread() bug --- citadel/config.c | 2 +- citadel/file_ops.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/citadel/config.c b/citadel/config.c index 4c2509f00..9d731d3e7 100644 --- a/citadel/config.c +++ b/citadel/config.c @@ -69,7 +69,7 @@ void get_config(void) { } memset(&config, 0, sizeof(struct config)); rv = fread((char *) &config, sizeof(struct config), 1, cfp); - if (rv != sizeof(struct config)) + if (rv != 1) { fprintf(stderr, "Warning: The config file %s has unexpected size. \n", diff --git a/citadel/file_ops.c b/citadel/file_ops.c index b81ba6bed..b7b0cb3f3 100644 --- a/citadel/file_ops.c +++ b/citadel/file_ops.c @@ -621,7 +621,6 @@ void cmd_read(char *cmdbuf) { long start_pos; size_t bytes; - size_t actual_bytes; char *buf = NULL; start_pos = extract_long(cmdbuf, 0); @@ -637,9 +636,13 @@ void cmd_read(char *cmdbuf) buf = malloc(bytes + 1); fseek(CC->download_fp, start_pos, 0); - actual_bytes = fread(buf, 1, bytes, CC->download_fp); - cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes); - client_write(buf, actual_bytes); + if (fread(buf, 1, bytes, CC->download_fp) == 1) { + cprintf("%d %d\n", BINARY_FOLLOWS, (int)bytes); + client_write(buf, bytes); + } + else { + cprintf("%d %s\n", ERROR, strerror(errno)); + } free(buf); } -- 2.30.2