From 6e7f38e81fcf47545a4cde9f1e15f6b35c47a014 Mon Sep 17 00:00:00 2001 From: MCUdude Date: Fri, 18 Feb 2022 08:33:09 +0100 Subject: [PATCH] Properly handle negative numbers Now -3.141592 and -32768 are valid numbers that's stored correctly in memory --- src/term.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/term.c b/src/term.c index 1d0bca98..84c9e243 100644 --- a/src/term.c +++ b/src/term.c @@ -428,9 +428,9 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p, } } buf[i - start_offset + bytes_grown] = (write_val >> 0) & 0xFF; - if (write_val > 0xFF || ptr) + if (labs(write_val) > 0xFF || ptr) buf[i - start_offset + ++bytes_grown] = (write_val >> 8) & 0xFF; - if (write_val > 0xFFFF || ptr) { + if (labs(write_val) > 0xFFFF || ptr) { buf[i - start_offset + ++bytes_grown] = (write_val >> 16) & 0xFF; buf[i - start_offset + ++bytes_grown] = (write_val >> 24) & 0xFF; }