gbranden pushed a commit to branch master in repository groff. commit ee0e2a5efc07fd40ef7345b87adf44c79f159738 Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Thu Jul 10 17:19:31 2025 -0500
[troff]: Trivially refactor. * src/roff/troff/input.cpp (read_rest_of_line_as_argument): Rename local variable `len` to `buf_size`, for consistency with several other functions in this file that handle memory buffers. Reorder equality comparisons to avoid inadvertent lvalue assignment. Parenthesize (formally) complex expressions. --- ChangeLog | 9 +++++++++ src/roff/troff/input.cpp | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3166a5a3a..7c3179a14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2025-07-10 G. Branden Robinson <g.branden.robin...@gmail.com> + + * src/roff/troff/input.cpp (read_rest_of_line_as_argument): + Trivially refactor. Rename local variable `len` to `buf_size`, + for consistency with several other functions in this file that + handle memory buffers. Reorder equality comparisons to avoid + inadvertent lvalue assignment. Parenthesize (formally) complex + expressions. + 2025-07-10 G. Branden Robinson <g.branden.robin...@gmail.com> * src/preproc/html/pre-html.cpp (get_line): Catch diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp index 71f01d599..61597922d 100644 --- a/src/roff/troff/input.cpp +++ b/src/roff/troff/input.cpp @@ -8707,23 +8707,23 @@ void abort_request() // The caller has responsibility for `delete`ing the returned array. char *read_rest_of_line_as_argument() { - int len = 256; - char *s = new char[len]; // C++03: new char[len](); - (void) memset(s, 0, (len * sizeof(char))); + int buf_size = 256; + char *s = new char[buf_size]; // C++03: new char[buf_size](); + (void) memset(s, 0, (buf_size * sizeof(char))); int c = get_copy(0 /* nullptr */); - while (c == ' ') + while (' ' == c) c = get_copy(0 /* nullptr */); - if (c == '"') + if ('"' == c) c = get_copy(0 /* nullptr */); int i = 0; - while (c != '\n' && c != EOF) { + while ((c != '\n') && (c != EOF)) { if (!is_invalid_input_char(c)) { - if (i + 2 > len) { + if ((i + 2) > buf_size) { char *tem = s; - s = new char[len * 2]; // C++03: new char[len * 2](); - (void) memset(s, 0, (len * 2 * sizeof(char))); - memcpy(s, tem, len); - len *= 2; + s = new char[buf_size * 2]; // C++03: new char[buf_size * 2](); + (void) memset(s, 0, (buf_size * 2 * sizeof(char))); + memcpy(s, tem, buf_size); + buf_size *= 2; delete[] tem; } s[i++] = c; @@ -8731,7 +8731,7 @@ char *read_rest_of_line_as_argument() c = get_copy(0 /* nullptr */); } s[i] = '\0'; - if (i == 0) { + if (0 == i) { delete[] s; return 0 /* nullptr */; } _______________________________________________ groff-commit mailing list groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit