From 05cf81283b90531710f060f7ef6e3216fe8b5330 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 1 Aug 2021 07:59:25 -0600 Subject: [PATCH] [util/hb-shape] Fix use of EOF as end-of-line EOF is -1, which was being treated as a valid char (255). Use int instead. --- test/api/test-style.c | 2 +- util/main-font-text.hh | 2 +- util/options.cc | 15 ++++++++------- util/options.hh | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/test/api/test-style.c b/test/api/test-style.c index 5e7282491..7ab66d144 100644 --- a/test/api/test-style.c +++ b/test/api/test-style.c @@ -166,5 +166,5 @@ main (int argc, char **argv) return hb_test_run (); } #else -int main () {} +int main (int argc, char **argv) {} #endif diff --git a/util/main-font-text.hh b/util/main-font-text.hh index 871a30465..7915c3786 100644 --- a/util/main-font-text.hh +++ b/util/main-font-text.hh @@ -47,7 +47,7 @@ locale_to_utf8 (char *s) return t; } -template +template struct main_font_text_t { main_font_text_t () diff --git a/util/options.cc b/util/options.cc index bec6bed9a..94595a8a7 100644 --- a/util/options.cc +++ b/util/options.cc @@ -797,7 +797,7 @@ font_options_t::get_font () const const char * -text_options_t::get_line (unsigned int *len, char eol) +text_options_t::get_line (unsigned int *len, int eol) { if (text) { if (!line) @@ -848,18 +848,19 @@ text_options_t::get_line (unsigned int *len, char eol) g_string_set_size (gs, 0); char buf[BUFSIZ]; - while (fgets (buf, sizeof (buf), fp)) { - unsigned int bytes = strlen (buf); - if (bytes && buf[bytes - 1] == eol) { + while (fgets (buf, sizeof (buf), fp)) + { + unsigned bytes = strlen (buf); + if (bytes && (int) (unsigned char) buf[bytes - 1] == eol) + { bytes--; g_string_append_len (gs, buf, bytes); break; } - g_string_append_len (gs, buf, bytes); + g_string_append_len (gs, buf, bytes); } if (ferror (fp)) - fail (false, "Failed reading text: %s", - strerror (errno)); + fail (false, "Failed reading text: %s", strerror (errno)); *len = gs->len; return !*len && feof (fp) ? nullptr : gs->str; } diff --git a/util/options.hh b/util/options.hh index 84bc593e5..11cd9b20b 100644 --- a/util/options.hh +++ b/util/options.hh @@ -563,7 +563,7 @@ struct text_options_t : option_group_t "Only one of text and text-file can be set"); } - const char *get_line (unsigned int *len, char eol = '\n'); + const char *get_line (unsigned int *len, int eol = '\n'); char *text_before; char *text_after;