aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org> 2017-08-02 11:07:02 +0200
committerGravatar Steven Schubiger <stsc@refcnt.org> 2017-08-02 11:07:02 +0200
commitef3ba3bb9a06cffad7b4530a88f36b871abe2e0d (patch)
tree468e6c243ba0f6a1e53dfe8605f997f4ac787301
parent13b184a21e6ede64a9cf16f20dd774ea8cd45c4f (diff)
downloadcolorize-ef3ba3bb9a06cffad7b4530a88f36b871abe2e0d.tar.gz
colorize-ef3ba3bb9a06cffad7b4530a88f36b871abe2e0d.tar.bz2
Optimize extracting invalid attribute name
-rw-r--r--colorize.c7
-rwxr-xr-xt/fail.t2
2 files changed, 4 insertions, 5 deletions
diff --git a/colorize.c b/colorize.c
index 1e27fca..8c0afcb 100644
--- a/colorize.c
+++ b/colorize.c
@@ -469,11 +469,10 @@ process_opt_attr (const char *p)
}
if (!valid_attr)
{
- char *sep;
- char *attr_invalid = xstrdup (s);
+ char *attr_invalid = xmalloc ((p - s) + 1);
STACK_VAR (attr_invalid);
- if ((sep = strchr (attr_invalid, ',')))
- *sep = '\0';
+ strncpy (attr_invalid, s, p - s);
+ attr_invalid[p - s] = '\0';
vfprintf_fail ("--attr switch attribute '%s' is not valid", attr_invalid);
}
}
diff --git a/t/fail.t b/t/fail.t
index e2d71be..10378c4 100755
--- a/t/fail.t
+++ b/t/fail.t
@@ -43,7 +43,7 @@ SKIP: {
[ '--attr=:', 'must be provided a string' ],
[ '--attr=bold:underscore', 'must have strings separated by ,' ],
[ '--attr=b0ld', 'attribute \'b0ld\' is not valid' ],
- [ '--attr=b0ld,underscore', 'attribute \'b0ld\' is not valid' ], # NULify comma
+ [ '--attr=b0ld,underscore', 'attribute \'b0ld\' is not valid' ], # handle comma
[ '--attr=bold,bold', 'has attribute \'bold\' twice or more' ],
[ '--exclude-random=random', 'must be provided a plain color' ],
[ '--clean --clean-all', 'mutually exclusive' ],