=================================================================== RCS file: /cvs/mandoc/chars.c,v retrieving revision 1.36 retrieving revision 1.41 diff -u -p -r1.36 -r1.41 --- mandoc/chars.c 2011/04/29 22:18:12 1.36 +++ mandoc/chars.c 2011/05/14 17:54:42 1.41 @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.36 2011/04/29 22:18:12 kristaps Exp $ */ +/* $Id: chars.c,v 1.41 2011/05/14 17:54:42 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -20,6 +20,7 @@ #endif #include +#include #include #include #include @@ -55,7 +56,6 @@ struct ln { #include "chars.in" struct mchars { - enum mcharst type; struct ln **htab; }; @@ -72,7 +72,7 @@ mchars_free(struct mchars *arg) } struct mchars * -mchars_init(enum mcharst type) +mchars_alloc(void) { struct mchars *tab; struct ln **htab; @@ -103,7 +103,6 @@ mchars_init(enum mcharst type) } tab->htab = htab; - tab->type = type; return(tab); } @@ -137,28 +136,25 @@ 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). */ -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. */ @@ -174,7 +170,6 @@ mchars_spec2str(struct mchars *arg, const char *p, siz *rsz = strlen(ln->ascii); return(ln->ascii); } - /* * Reserved word to string array.