From 2f0a2dd8ef3dfd40457fb5a0b14a7c1a00b43fdc Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 17 Apr 2022 15:57:49 -0700 Subject: Fix whitespace/maxlinesize handling in p8bin2uart. --- tool/p8bin2uart.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tool') diff --git a/tool/p8bin2uart.c b/tool/p8bin2uart.c index 944227a..de5a328 100644 --- a/tool/p8bin2uart.c +++ b/tool/p8bin2uart.c @@ -146,13 +146,13 @@ print(const char *fmt, ...) va_start(args, fmt); vsnprintf(tmp, size, fmt, args); va_end(args); - strncat(buf, tmp, MAX_LINE_SIZE * 2 - 1); + strcat(buf, tmp); if (strlen(buf) > MAX_LINE_SIZE) { char *space = strrchr(buf, ' '); assert(space); assert(space - buf <= MAX_LINE_SIZE); - *space = 0; - ++space; + assert(*space == ' '); + *space++ = '\0'; assert(strlen(buf) <= MAX_LINE_SIZE); printf("%s\n", buf); memmove(buf, space, buf + sizeof(buf) - space); @@ -181,18 +181,17 @@ dump(unsigned int wordsperline) if (allzero) continue; if (nextaddr != a) { if (nextaddr + wordsperline == a) - print("= "); + print(" ="); else - print("!%x ", (unsigned int)((a - nextaddr) / wordsperline)); + print(" !%x", (unsigned int)((a - nextaddr) / wordsperline)); } - print("="); + print(" ="); for (uint_fast32_t i = 0; i < wordsperline; ++i) print(i == 0 ? "%x" : ":%04x", (unsigned int)words[i]); - print(" "); nextaddr = a + wordsperline; } if (nextaddr != 32768) - print("!%x\n", (unsigned int)((32768 - nextaddr) / wordsperline)); + print(" !%x\n", (unsigned int)((32768 - nextaddr) / wordsperline)); flush(); } -- cgit v1.2.3