]> git.refcnt.org Git - colorize.git/commitdiff
Optimize extracting invalid attribute name
authorSteven Schubiger <stsc@refcnt.org>
Wed, 2 Aug 2017 09:07:02 +0000 (11:07 +0200)
committerSteven Schubiger <stsc@refcnt.org>
Wed, 2 Aug 2017 09:07:02 +0000 (11:07 +0200)
colorize.c
t/fail.t

index 1e27fcae01878ea6f41c90adac3c52aa7138317b..8c0afcbe36725ea6402a63ec77b3d1fa05f9126b 100644 (file)
@@ -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);
               }
           }
index e2d71beb121c1fa58acad76208097c6d906fb02a..10378c412548fc694ad1e711dbf3c983b19d82fd 100755 (executable)
--- 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'                          ],