From: Christian Heller Date: Thu, 15 Aug 2013 11:43:53 +0000 (+0200) Subject: Added explanatory comments to readwrite library. X-Git-Tag: tce~1095 X-Git-Url: https://plomlompom.com/repos/%7B%7Byoutube_prefix%7D%7D%7B%7Bvideo_data.id_%7D%7D?a=commitdiff_plain;h=ad3f7d4d420b5447d756be1eaaf78f0abd1a5f65;p=plomrogue Added explanatory comments to readwrite library. --- diff --git a/src/readwrite.c b/src/readwrite.c index 039dade..2b6823a 100644 --- a/src/readwrite.c +++ b/src/readwrite.c @@ -58,6 +58,11 @@ static uint8_t write_uintX_bigendian(FILE * file, uint32_t x, uint8_t size) extern uint8_t read_uint8(FILE * file, uint8_t * x) { + /* Since read_uintX_bigendian() works on -- and zeroes -- four bytes, work + * on values of fewer bytes corrupts their immediate neighbor bytes. This + * necessitates working on newly acquired separate memory areas (* y), only + * copying the sufficiently small end result to * x. + */ uint32_t y = * x; uint8_t err = read_uintX_bigendian(file, &y, 8); * x = (uint8_t) y; @@ -68,6 +73,7 @@ extern uint8_t read_uint8(FILE * file, uint8_t * x) extern uint8_t read_uint16_bigendian(FILE * file, uint16_t * x) { + /* See read_uint8() introductory comment for rationale. */ uint32_t y = * x; uint8_t err = read_uintX_bigendian(file, &y, 16); * x = (uint16_t) y;