From f8a87041352ebc0a3161e958cc640f674dca9715 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Mon, 29 Oct 2018 22:29:53 -0400 Subject: [PATCH] ntoa: fix bits_ntoa formatting and error handling Get rid of an assert in bits_ntoa. Throw an exception instead. Fix hex formatting (adding "0x" before a decimal number is not the correct way to format hex strings). Signed-off-by: Zygo Blaxell --- lib/ntoa.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/ntoa.cc b/lib/ntoa.cc index f512d1f..82999c5 100644 --- a/lib/ntoa.cc +++ b/lib/ntoa.cc @@ -1,8 +1,7 @@ #include "crucible/ntoa.h" -#include -#include -#include +#include "crucible/error.h" +#include "crucible/string.h" namespace crucible { using namespace std; @@ -12,7 +11,7 @@ namespace crucible { string out; while (n && table->a) { // No bits in n outside of mask - assert( ((~table->mask) & table->n) == 0); + THROW_CHECK2(invalid_argument, table->mask, table->n, ((~table->mask) & table->n) == 0); if ( (n & table->mask) == table->n) { if (!out.empty()) { out += "|"; @@ -23,12 +22,10 @@ namespace crucible { ++table; } if (n) { - ostringstream oss; - oss << "0x" << hex << n; if (!out.empty()) { out += "|"; } - out += oss.str(); + out += to_hex(n); } if (out.empty()) { out = "0";