summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-01-07 10:24:43 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-01-07 10:24:43 +0000
commitad3053cbf11882fc2478adedbd82aadb0b6f9ca9 (patch)
tree18b2912353652906bf4d1c4eb4baf77b0faf88ed
parent65a5d430e92f93dd778bf5b4aaabe7e52238d532 (diff)
downloadmandoc-ad3053cbf11882fc2478adedbd82aadb0b6f9ca9.tar.gz
Check for white-space at the end of free-form text. Lack of check spotted by Jason McIntyre.
-rw-r--r--man.c26
-rw-r--r--mdoc.c15
2 files changed, 38 insertions, 3 deletions
diff --git a/man.c b/man.c
index 71ae2c42..35465c3a 100644
--- a/man.c
+++ b/man.c
@@ -365,6 +365,7 @@ static int
man_ptext(struct man *m, int line, char *buf)
{
int i, j;
+ char sv;
/* Literal free-form text whitespace is preserved. */
@@ -379,7 +380,11 @@ man_ptext(struct man *m, int line, char *buf)
for (i = 0; ' ' == buf[i]; i++)
/* Skip leading whitespace. */ ;
- if (0 == buf[i]) {
+ if ('\0' == buf[i]) {
+ /* Trailing whitespace? */
+ if (i && ' ' == buf[i - 1])
+ if ( ! man_pwarn(m, line, i - 1, WTSPACE))
+ return(0);
if ( ! pstring(m, line, 0, &buf[i], 0))
return(0);
goto descope;
@@ -393,15 +398,30 @@ man_ptext(struct man *m, int line, char *buf)
if (i && ' ' == buf[i] && '\\' == buf[i - 1])
continue;
- buf[i++] = 0;
+ sv = buf[i];
+ buf[i++] = '\0';
+
if ( ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
return(0);
+ /* Trailing whitespace? Check at overwritten byte. */
+
+ if (' ' == sv && '\0' == buf[i])
+ if ( ! man_pwarn(m, line, i - 1, WTSPACE))
+ return(0);
+
for ( ; ' ' == buf[i]; i++)
/* Skip trailing whitespace. */ ;
j = i;
- if (0 == buf[i])
+
+ /* Trailing whitespace? */
+
+ if (' ' == buf[i - 1] && '\0' == buf[i])
+ if ( ! man_pwarn(m, line, i - 1, WTSPACE))
+ return(0);
+
+ if ('\0' == buf[i])
break;
}
diff --git a/mdoc.c b/mdoc.c
index 9c24880e..0d3925ff 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -581,6 +581,7 @@ static int
parsetext(struct mdoc *m, int line, char *buf)
{
int i, j;
+ char sv;
if (SEC_NONE == m->lastnamed)
return(mdoc_perr(m, line, 0, ETEXTPROL));
@@ -614,15 +615,29 @@ parsetext(struct mdoc *m, int line, char *buf)
if (i && ' ' == buf[i] && '\\' == buf[i - 1])
continue;
+ sv = buf[i];
buf[i++] = '\0';
if ( ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
return(0);
+ /* Trailing whitespace? Check at overwritten byte. */
+
+ if (' ' == sv && '\0' == buf[i])
+ if ( ! mdoc_pwarn(m, line, i - 1, ETAILWS))
+ return(0);
+
for ( ; ' ' == buf[i]; i++)
/* Skip trailing whitespace. */ ;
j = i;
+
+ /* Trailing whitespace? */
+
+ if (' ' == buf[i - 1] && '\0' == buf[i])
+ if ( ! mdoc_pwarn(m, line, i - 1, ETAILWS))
+ return(0);
+
if ('\0' == buf[i])
break;
}