From c6fc8190de226d26d73b7bd460068b89bf6c62eb Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 20 Jun 2012 16:51:40 -0300 Subject: [PATCH] fw/image.c: fix use of hash functions; make image pointer setup more readable It was almost impossible NOT to read next_image = p = image == images[0] ? ... ^^^^ as if it was next_image = p = image = images[0] ? ... ^^^ --- fw/image.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fw/image.c b/fw/image.c index dd07d4b..f5961b9 100644 --- a/fw/image.c +++ b/fw/image.c @@ -64,7 +64,12 @@ static void add_payload(const uint8_t *payload) static bool image_first(const uint8_t *payload) { hash_init(); - next_image = p = image == images[0] ? images[1] : images[0]; + hash_merge(image_secret, sizeof(image_secret)); + if (image == images[0]) + p = images[1]; + else + p = images[0]; + next_image = p; end = p+MAX_LINES; memset(p, 0, (char *) end-(char *) p); add_payload(payload); @@ -85,6 +90,7 @@ static bool image_more(uint8_t seq, uint8_t limit, const uint8_t *payload) hash_merge(payload, PAYLOAD); break; case 1: + hash_end(); failed = !hash_eq(payload, PAYLOAD, 0); break; case 0: