Update of bug #64155 (project groff): Summary: specifying -fZD on command line generates warnings => [PATCH] specifying -fZD on command line generates warnings
_______________________________________________________ Follow-up Comment #11: Here's what I've pushed to my working copy. diff --git a/ChangeLog b/ChangeLog index 79163d005..b91609090 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2023-05-25 G. Branden Robinson <g.branden.robin...@gmail.com> + + [troff]: Validate a font family before trying to use it. + + * src/roff/troff/env.cpp (is_family_valid): New function checks + for all text styles (R, I, B, BI) and returns true only if the + given family supports them all. + (family_change): Call `is_family_valid()` on given argument. + If invalid, throw diagnostic and ignore `fam` request. + * src/roff/troff/env.h (is_family_valid): Declare; make visible. + * src/roff/troff/input.cpp (main): Call `is_family_valid()` on + `-f` option argument. Its invalidity is a fatal error. + + Fixes <https://savannah.gnu.org/bugs/?64115>. Thanks to Dave + Kemper for the report. + 2023-05-25 G. Branden Robinson <g.branden.robin...@gmail.com> * src/roff/troff/env.h (read_hyphen_file): Drop relic prototype diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp index 4c64273ef..fc14cb715 100644 --- a/src/roff/troff/env.cpp +++ b/src/roff/troff/env.cpp @@ -1256,9 +1256,32 @@ void font_change() skip_line(); } +bool is_family_valid(const char *fam) +{ + // std::vector<const char *> styles{"R", "I", "B", "BI"}; // C++11 + std::vector<const char *> styles; + styles.reserve(4); + styles.push_back("R"); + styles.push_back("I"); + styles.push_back("B"); + styles.push_back("BI"); + std::vector<const char *>::iterator style; + // for (auto style : styles) // C++11 + for (style = styles.begin(); style != styles.end(); style++) + if (!check_font(fam, *style)) + return false; + return true; +} + void family_change() { symbol s = get_name(); + if (s != 0 /* nullptr */) + if (!is_family_valid(s.contents())) { + error("'%1' is not a valid font family", s.contents()); + skip_line(); + return; + } curenv->set_family(s); skip_line(); } diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h index d98941914..8382d11ea 100644 --- a/src/roff/troff/env.h +++ b/src/roff/troff/env.h @@ -408,6 +408,7 @@ extern void pop_env(); extern void push_env(int); void init_environments(); +bool is_family_valid(const char *); extern double spread_limit; diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp index cbb8b1ca3..56c20f3eb 100644 --- a/src/roff/troff/input.cpp +++ b/src/roff/troff/input.cpp @@ -8333,6 +8333,9 @@ int main(int argc, char **argv) warning(WARN_FONT, "cannot mount font '%1' directed by 'DESC'" " file for device '%2'", font::font_name_table[i], device); + if (fflag && !(is_family_valid(default_family.contents()))) + fatal("'%1' is not a valid font family", + default_family.contents()); curdiv = topdiv = new top_level_diversion; if (nflag) topdiv->set_next_page_number(next_page_number); _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/bugs/?64155> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/