summaryrefslogtreecommitdiff
path: root/src/preproc/html
diff options
context:
space:
mode:
authorG. Branden Robinson <g.branden.robinson@gmail.com>2022-06-28 10:48:33 -0500
committerG. Branden Robinson <g.branden.robinson@gmail.com>2022-07-01 20:30:58 -0500
commit665953f8026f25c4fc820e68e8a901531e1b2445 (patch)
treea7df9d63465c676f8080af49ba9b58d3e5fb9f77 /src/preproc/html
parent4d1d60cd1c188160735ebc9861d0a07fa3504f81 (diff)
downloadgroff-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.
Diffstat (limited to 'src/preproc/html')
-rw-r--r--src/preproc/html/pre-html.cpp23
1 files changed, 13 insertions, 10 deletions
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 },