gbranden pushed a commit to branch master
in repository groff.
commit 7b85efe63117bf9d6d33911dc962bd33a611ea50
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Dec 25 18:58:23 2025 -0600
src/roff/troff/input.cpp: Work on Savannah #67735.
* src/roff/troff/input.cpp (do_define_macro): Assign `char`-valued
literals to temporary `int` storing value we got from
`read_char_in_copy_mode()` (which calls `input_iterator::fill()`,
which in turn calls getc(3)), since it is destined to become an input
character--if we don't have to handle EOF. Since we must, drop
C-style type casts to `unsigned char` while still scanning input.
Absence of a premature EOF established, use `static_cast` operator to
demote this `int` to `unsigned char` before appending it to a macro.
---
ChangeLog | 12 ++++++++++++
src/roff/troff/input.cpp | 31 ++++++++++++++++---------------
2 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7443d85ce..1a48788b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2025-12-25 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/input.cpp (do_define_macro): Work on Savannah
+ #67735. Assign `char`-valued literals to temporary `int`
+ storing value we got from `read_char_in_copy_mode()` (which
+ calls `input_iterator::fill()`, which in turn calls getc(3)),
+ since it is destined to become an input character--if we don't
+ have to handle EOF. Since we must, drop C-style type casts to
+ `unsigned char` while still scanning input. Absence of a
+ premature EOF established, use `static_cast` operator to demote
+ this `int` to `unsigned char` before appending it to a macro.
+
2025-12-25 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (do_define_macro): Improve
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 50dcb5290..2fa24fdbd 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5453,30 +5453,30 @@ void do_define_macro(define_mode mode, calling_mode
calling, comp_mode comp)
mac.clear_string_flag();
while (c == ESCAPE_NEWLINE) {
if (mode == DEFINE_NORMAL || mode == DEFINE_APPEND)
- // TODO: convert to unsigned char (future: grochar)?
- mac.append(c);
+ // TODO: grochar; may need NFD decomposition and UTF-8 encoding
+ mac.append(static_cast<unsigned char>(c));
c = read_char_in_copy_mode(&n, true /* is_defining */);
}
if (reading_beginning_of_input_line && (c == '.')) {
const char *s = term.contents();
- int d = 0;
+ int d = '\0';
// see if it matches term
int i = 0;
- if (s[0] != 0) {
+ if (s[0] != '\0') {
while (((d = read_char_in_copy_mode(&n)) == ' ') || (d == '\t'))
;
- if ((unsigned char) s[0] == d) {
- for (i = 1; s[i] != 0; i++) {
+ if (s[0] == d) {
+ for (i = 1; s[i] != '\0'; i++) {
d = read_char_in_copy_mode(&n);
- if ((unsigned char) s[i] != d)
+ if (s[i] != d)
break;
}
}
}
- if (s[i] == 0
+ if (s[i] == '\0'
&& (((i == 2) && want_att_compat)
|| ((d = read_char_in_copy_mode(&n)) == ' ')
- || d == '\n')) { // we found it
+ || (d == '\n'))) { // we found it
if (d == '\n')
tok.make_newline();
else
@@ -5499,10 +5499,11 @@ void do_define_macro(define_mode mode, calling_mode
calling, comp_mode comp)
return;
}
if ((mode == DEFINE_APPEND) || (mode == DEFINE_NORMAL)) {
- // TODO: convert to unsigned char (future: grochar)?
- mac.append(c);
+ // TODO: grochar; may need NFD decomposition and UTF-8 encoding
+ mac.append(static_cast<unsigned char>(c));
for (int j = 0; j < i; j++)
- mac.append(s[j]);
+ // TODO: grochar; may need NFD decomposition & UTF-8 encoding
+ mac.append(static_cast<unsigned char>(s[j]));
}
c = d;
}
@@ -5528,11 +5529,11 @@ void do_define_macro(define_mode mode, calling_mode
calling, comp_mode comp)
return;
}
if ((mode == DEFINE_NORMAL) || (mode == DEFINE_APPEND)) {
- if (c == 0)
+ if (c == '\0')
mac.append(n);
else
- // TODO: convert to unsigned char (future: grochar)?
- mac.append(c);
+ // TODO: grochar; may need NFD decomposition and UTF-8 encoding
+ mac.append(static_cast<unsigned char>(c));
}
reading_beginning_of_input_line = (c == '\n');
c = read_char_in_copy_mode(&n, true /* is_defining */);
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit