From 1c8f00e90daa8f20bfd0763f09af8c5c1d76c6ab Mon Sep 17 00:00:00 2001 From: Cary R Date: Sat, 1 Jan 2011 15:46:42 -0800 Subject: [PATCH] V0.9: Fix the display of characters with the MSB set (cast to unsigned char). When a verinum is displayed as a string we need to make sure that any character that will be displayed as an octal constant must be converted correctly. Also change to isprint() instead of isgraph() since it is the same as isgraph() plus a space. --- lexor.lex | 6 +++--- verinum.cc | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lexor.lex b/lexor.lex index 444d6a10d..affd9d794 100644 --- a/lexor.lex +++ b/lexor.lex @@ -620,14 +620,14 @@ S [afpnumkKMGT] error_count += 1; } /* Final catchall. something got lost or mishandled. */ - /* XXX Should we tell the luser something about the lexical state? */ + /* XXX Should we tell the user something about the lexical state? */ <*>.|\n { cerr << yylloc.text << ":" << yylloc.first_line << ": error: unmatched character ("; - if (isgraph(yytext[0])) + if (isprint(yytext[0])) cerr << yytext[0]; else - cerr << "hex " << hex << (0xffU & ((unsigned) (yytext[0]))); + cerr << "hex " << hex << ((unsigned char) yytext[0]); cerr << ")" << endl; error_count += 1; } diff --git a/verinum.cc b/verinum.cc index 4e7be7668..99dd3ec6e 100644 --- a/verinum.cc +++ b/verinum.cc @@ -516,11 +516,11 @@ string verinum::as_string() const char tmp[5]; snprintf(tmp, sizeof tmp, "\\%03o", char_val); res = res + tmp; - } else if (char_val == ' ' || isgraph(char_val)) { + } else if (isprint(char_val)) { res = res + char_val; } else { char tmp[5]; - snprintf(tmp, sizeof tmp, "\\%03o", char_val); + snprintf(tmp, sizeof tmp, "\\%03o", (unsigned char)char_val); res = res + tmp; } }