From f7997ca157a639f4aac10cdf6f15de03f34c6d7f Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 16 Nov 2020 00:02:29 +0000 Subject: [PATCH] fixed array initialisation bug --- include/hex.hpp | 3 +++ src/hex.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/hex.hpp b/include/hex.hpp index aacfa97..3e06487 100644 --- a/include/hex.hpp +++ b/include/hex.hpp @@ -31,6 +31,9 @@ namespace hv { { int pos = (x & 0xFF) * 2; char ch = lut[pos]; +#ifdef DEBUG + if ( (i*2+1) >=16) std::terminate(); +#endif s[i * 2] = ch; ch = lut[pos + 1]; diff --git a/src/hex.cpp b/src/hex.cpp index 9b045e3..c0996ea 100644 --- a/src/hex.cpp +++ b/src/hex.cpp @@ -88,18 +88,20 @@ namespace hv { #define S #define P_EX(n, buf) print_exact(buf) #endif - char posbuf[3 + 16 + 2] = { '0' }; + char posbuf[3 + 16 + 2]; posbuf[0] = '\n'; posbuf[1] = '0'; posbuf[2] = 'x'; - +#ifdef DEBUG + std::memset(posbuf+3, '0', 16); +#endif posbuf[3 + 16] = ' '; posbuf[3 + 16 + 1] = ' '; u64_to_hex(offset, posbuf+3); prints(posbuf+1); - char hxbuf[3] = { ' ' }; + char hxbuf[3] = { ' ', ' ', ' ' }; std::size_t i=0; char r_ascii[2 + ROW_SZ]; r_ascii[0] = ' '; @@ -124,7 +126,7 @@ namespace hv { { auto rest = memsize % ROW_SZ; ascii[rest] = 0; - constexpr const char output[3] = { ' ' }; + constexpr const char output[3] = { ' ', ' ', ' ' }; for(std::size_t j=0;j< ROW_SZ - rest;j++) print_exact(output);