diff options
author | G. Branden Robinson <g.branden.robinson@gmail.com> | 2022-06-28 10:48:33 -0500 |
---|---|---|
committer | G. Branden Robinson <g.branden.robinson@gmail.com> | 2022-07-01 20:30:58 -0500 |
commit | 665953f8026f25c4fc820e68e8a901531e1b2445 (patch) | |
tree | a7df9d63465c676f8080af49ba9b58d3e5fb9f77 | |
parent | 4d1d60cd1c188160735ebc9861d0a07fa3504f81 (diff) | |
download | groff-git-665953f8026f25c4fc820e68e8a901531e1b2445.tar.gz |
src/preproc/html/pre-html.cpp: Refactor (7/11).
* src/preproc/html/pre-html.cpp (makeFileName, scanArguments): Dismiss
Shlemiel the Painter: save return value of `strlen()` and call
`strcpy()` multiple times instead of mixing `strcpy()` and `strcat()`;
the latter approach rescans the string unnecessarily.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/preproc/html/pre-html.cpp | 23 |
2 files changed, 18 insertions, 11 deletions
@@ -1,4 +1,4 @@ -2022-06-27 G. Branden Robinson <g.branden.robinson@gmail.com> +2022-06-28 G. Branden Robinson <g.branden.robinson@gmail.com> * src/preproc/html/pre-html.cpp: Refactor. Drop unnecessary prototype for static function. @@ -13,6 +13,10 @@ (makeFileName, checkImageDir, char_buffer::run_output_filter, scanArguments): Call `fatal()` instead of `error()` and then `exit(1)`. + (makeFileName, scanArguments): Dismiss Shlemiel the Painter: + save return value of `strlen()` and call `strcpy()` multiple + times instead of mixing `strcpy()` and `strcat()`; the latter + approach rescans the string unnecessarily. (char_buffer::run_output_filter): Stop passing unnecessary null pointer argument to diagnostic message functions. Stop calling `fflush()` after libgroff diagnostic function, which always diff --git a/src/preproc/html/pre-html.cpp b/src/preproc/html/pre-html.cpp index e8a3175e1..722eee8c4 100644 --- a/src/preproc/html/pre-html.cpp +++ b/src/preproc/html/pre-html.cpp @@ -572,13 +572,14 @@ static void makeFileName(void) if (macroset_template == NULL) sys_fatal("make_message"); - image_template = - (char *)malloc(strlen("%d") + strlen(macroset_template) + 1); + size_t mtlen = strlen(macroset_template); + image_template = (char *)malloc(strlen("%d") + mtlen + 1); if (image_template == NULL) sys_fatal("malloc"); - strcpy(image_template, macroset_template); + char *s = strcpy(image_template, macroset_template); + s += mtlen; // Keep this format string synced with troff:suppress_node::tprint(). - strcat(image_template, "%d"); + strcpy(s, "%d"); } /* @@ -1600,12 +1601,14 @@ static void usage(FILE *stream) static int scanArguments(int argc, char **argv) { - const char *command_prefix = getenv("GROFF_COMMAND_PREFIX"); - if (!command_prefix) - command_prefix = PROG_PREFIX; - char *troff_name = new char[strlen(command_prefix) + strlen("troff") + 1]; - strcpy(troff_name, command_prefix); - strcat(troff_name, "troff"); + const char *cmdprefix = getenv("GROFF_COMMAND_PREFIX"); + if (!cmdprefix) + cmdprefix = PROG_PREFIX; + size_t pfxlen = strlen(cmdprefix); + char *troff_name = new char[pfxlen + strlen("troff") + 1]; + char *s = strcpy(troff_name, cmdprefix); + s += pfxlen; + strcpy(s, "troff"); int c, i; static const struct option long_options[] = { { "help", no_argument, 0, CHAR_MAX + 1 }, |