=================================================================== RCS file: /cvs/mandoc/chars.c,v retrieving revision 1.38 retrieving revision 1.42 diff -u -p -r1.38 -r1.42 --- mandoc/chars.c 2011/04/30 22:14:42 1.38 +++ mandoc/chars.c 2011/05/15 15:47:46 1.42 @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.38 2011/04/30 22:14:42 kristaps Exp $ */ +/* $Id: chars.c,v 1.42 2011/05/15 15:47:46 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -20,6 +20,7 @@ #endif #include +#include #include #include #include @@ -135,28 +136,26 @@ mchars_res2cp(struct mchars *arg, const char *p, size_ return(ln->unicode); } - /* - * Numbered character to literal character, - * represented as a null-terminated string for additional safety. + * Numbered character to literal character. + * This can only be a printable character (i.e., alnum, punct, space) so + * prevent the character from ruining our state (backspace, newline, and + * so on). + * If the character is illegal, returns '\0'. */ -const char * +char mchars_num2char(const char *p, size_t sz) { int i; - static char c[2]; if (sz > 3) - return(NULL); + return('\0'); + i = atoi(p); - if (i < 0 || i > 255) - return(NULL); - c[0] = (char)i; - c[1] = '\0'; - return(c); + /* LINTED */ + return(isprint(i) ? i : '\0'); } - /* * Special character to string array. */ @@ -172,7 +171,6 @@ mchars_spec2str(struct mchars *arg, const char *p, siz *rsz = strlen(ln->ascii); return(ln->ascii); } - /* * Reserved word to string array.