=================================================================== RCS file: /cvs/mandoc/mandoc.c,v retrieving revision 1.85 retrieving revision 1.91 diff -u -p -r1.85 -r1.91 --- mandoc/mandoc.c 2014/08/16 19:00:01 1.85 +++ mandoc/mandoc.c 2015/01/21 20:33:25 1.91 @@ -1,7 +1,7 @@ -/* $Id: mandoc.c,v 1.85 2014/08/16 19:00:01 schwarze Exp $ */ +/* $Id: mandoc.c,v 1.91 2015/01/21 20:33:25 schwarze Exp $ */ /* - * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze + * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons + * Copyright (c) 2011-2015 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -79,24 +79,13 @@ mandoc_escape(const char **end, const char **start, in break; case '[': gly = ESCAPE_SPECIAL; - /* - * Unicode escapes are defined in groff as \[uXXXX] to - * \[u10FFFF], where the contained value must be a valid - * Unicode codepoint. Here, however, only check whether - * it's not a zero-width escape. - */ - if ('u' == (*start)[0] && ']' != (*start)[1]) - gly = ESCAPE_UNICODE; term = ']'; break; case 'C': if ('\'' != **start) return(ESCAPE_ERROR); *start = ++*end; - if ('u' == (*start)[0] && '\'' != (*start)[1]) - gly = ESCAPE_UNICODE; - else - gly = ESCAPE_SPECIAL; + gly = ESCAPE_SPECIAL; term = '\''; break; @@ -167,16 +156,18 @@ mandoc_escape(const char **end, const char **start, in /* FALLTHROUGH */ case 'D': /* FALLTHROUGH */ - case 'o': - /* FALLTHROUGH */ case 'R': /* FALLTHROUGH */ case 'X': /* FALLTHROUGH */ case 'Z': - if ('\0' == **start) - return(ESCAPE_ERROR); gly = ESCAPE_IGNORE; + /* FALLTHROUGH */ + case 'o': + if (**start == '\0') + return(ESCAPE_ERROR); + if (gly == ESCAPE_ERROR) + gly = ESCAPE_OVERSTRIKE; term = **start; *start = ++*end; break; @@ -199,7 +190,8 @@ mandoc_escape(const char **end, const char **start, in /* FALLTHROUGH */ case 'x': if (strchr(" %&()*+-./0123456789:<=>", **start)) { - ++*end; + if ('\0' != **start) + ++*end; return(ESCAPE_ERROR); } gly = ESCAPE_IGNORE; @@ -235,7 +227,7 @@ mandoc_escape(const char **end, const char **start, in /* See +/- counts as a sign. */ if ('+' == **end || '-' == **end || ASCII_HYPH == **end) - (*end)++; + *start = ++*end; switch (**end) { case '(': @@ -343,6 +335,21 @@ mandoc_escape(const char **end, const char **start, in case ESCAPE_SPECIAL: if (1 == *sz && 'c' == **start) gly = ESCAPE_NOSPACE; + /* + * Unicode escapes are defined in groff as \[u0000] + * to \[u10FFFF], where the contained value must be + * a valid Unicode codepoint. Here, however, only + * check the length and range. + */ + if (**start != 'u' || *sz < 5 || *sz > 7) + break; + if (*sz == 7 && ((*start)[1] != '1' || (*start)[2] != '0')) + break; + if (*sz == 6 && (*start)[1] == '0') + break; + if ((int)strspn(*start + 1, "0123456789ABCDEFabcdef") + + 1 == *sz) + gly = ESCAPE_UNICODE; break; default: break; @@ -475,6 +482,8 @@ time2a(time_t t) int isz; tm = localtime(&t); + if (tm == NULL) + return(NULL); /* * Reserve space: