From 8b01d8b204a10d90848cbbe8783042c3f8a29a53 Mon Sep 17 00:00:00 2001 From: Nathan Rosenquist Date: Sat, 1 Sep 2018 20:44:41 -0400 Subject: [PATCH] Use fread() return value to count bytes This commit changes the behavior of dcc6502, so that it consults the return value of fread(), and then increments the value of byte_count by the number returned by fread(), rather than implicitly incrementing it every time. Previously, a warning occurred during compilation, because the return value of fread() was ignored. Instead, the number of bytes in the input file were counted implicitly by incrementing a byte_count variable after every fread() call. Additionally, I created a two-byte test input file consisting of the bytes #$a9ff, which corresponds to LDA #$FF. When dcc6502 tried to disassemble this input file, it reported that the file had a size of three bytes. It reported the first two opcodes correctly, but then incorrectly displayed a BRK as the third opcode. After this change, the input file now has a reported size of two bytes, without the phantom BRK opcode at the end. --- dcc6502.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dcc6502.c b/dcc6502.c index 83d6aa3..8dc171f 100644 --- a/dcc6502.c +++ b/dcc6502.c @@ -769,8 +769,8 @@ int main(int argc, char *argv[]) { byte_count = 0; while(!feof(input_file) && ((options.org + byte_count) <= 0xFFFFu) && (byte_count < options.max_num_bytes)) { - fread(&buffer[options.org + byte_count], 1, 1, input_file); - byte_count++; + size_t bytes_read = fread(&buffer[options.org + byte_count], 1, 1, input_file); + byte_count += bytes_read; } fclose(input_file);