From a2a7c9bff97b90b3a480289a8fef5b794d98a90e Mon Sep 17 00:00:00 2001 From: Cary R Date: Sat, 1 Jan 2011 15:40:36 -0800 Subject: [PATCH] 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 ff96863c4..8ad0ed1ab 100644 --- a/lexor.lex +++ b/lexor.lex @@ -644,14 +644,14 @@ TU [munpf] 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 733e76915..712098b3d 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; } }