gbranden pushed a commit to branch master
in repository groff.
commit 0f49e6b5ee1ec575ed42e55be388009a16320516
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Nov 29 14:20:22 2023 -0600
[troff]: Improve `hcode` request validation.
* src/roff/troff/input.cpp (set_hyphenation_codes): Throw warning
diagnostic if no arguments supplied. Throw error diagnostic if there
are an odd number of arguments. Check second arguments of pairs for
nonsense.
Also:
* Annotate null pointers with `nullptr` comment to ease any future
transition to C++11, which defines it as a keyword.
* Reorder comparison to avoid inadvertent lvalue assignment.
Input:
$ nl hcode.groff
1 .hcode
2 .hcode \:
3 .hcode a
4 .hcode a\:
5 .hcode aA
Before:
$ groff -ww hcode.groff
troff:hcode.groff:2: error: expected ordinary or special character, got an
escaped ':'
troff:hcode.groff:3: error: hyphenation code must be ordinary character
troff:hcode.groff:4: error: hyphenation code must be ordinary character
After:
$ ./build/test-groff -ww hcode.groff
troff:hcode.groff:1: warning: hyphenation code configuration request
expects arguments
troff:hcode.groff:2: error: expected ordinary or special character, got an
escaped ':'
troff:hcode.groff:3: error: hyphenation codes must be specified in pairs
troff:hcode.groff:4: error: expected ordinary or special character, got an
escaped ':'
---
ChangeLog | 9 +++++++++
src/roff/troff/input.cpp | 19 ++++++++++++++++---
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 51c5c537b..4a16ebf0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-11-29 G. Branden Robinson <[email protected]>
+
+ [troff]: Improve `hcode` request validation.
+
+ * src/roff/troff/input.cpp (set_hyphenation_codes): Throw
+ warning diagnostic if no arguments supplied. Throw error
+ diagnostic if there are an odd number of arguments. Check
+ second arguments of pairs for nonsense.
+
2023-11-29 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (hyphenation_code): Rename to...
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index daf3e50f7..1166e24b3 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7231,17 +7231,30 @@ static void set_character_flags()
static void set_hyphenation_codes()
{
tok.skip();
+ if (tok.is_newline() || tok.is_eof()) {
+ warning(WARN_MISSING, "hyphenation code configuration request"
+ " expects arguments");
+ skip_line();
+ return;
+ }
while (!tok.is_newline() && !tok.is_eof()) {
charinfo *ci = tok.get_char(true /* required */);
- if (ci == 0)
+ // If we got back some nonsense like a non-character escape
+ // sequence, get_char() will have diagnosed it.
+ if (0 /* nullptr */ == ci)
break;
tok.next();
tok.skip();
unsigned char c = tok.ch();
- if (c == 0) {
- error("hyphenation code must be ordinary character");
+ if (tok.is_newline() || tok.is_eof()) {
+ error("hyphenation codes must be specified in pairs");
break;
}
+ charinfo *ci2 = tok.get_char(true /* required */);
+ // nonsense redux
+ if (0 /* nullptr */ == ci2)
+ break;
+ // TODO: What if you want to unset a hyphenation code? Accept 0?
if (csdigit(c)) {
error("hyphenation code cannot be digit");
break;
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit