color.c: trim leading spaces in color_parse_mem()
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 19 Jan 2017 11:41:22 +0000 (18:41 +0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 19 Jan 2017 19:22:01 +0000 (11:22 -0800)
Normally color_parse_mem() is called from config parser which trims the
leading spaces already. The new caller in the next patch won't. Let's be
tidy and trim leading spaces too (we already trim trailing spaces
after a word).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
color.c
diff --git a/color.c b/color.c
index a9eadd190a8c44fe4e670112705478b5a8c8492d..7bb4a96f8c1dfb0b5769829a133cd8a86d8beee6 100644 (file)
--- a/color.c
+++ b/color.c
@@ -207,10 +207,15 @@ int color_parse_mem(const char *value, int value_len, char *dst)
        struct color fg = { COLOR_UNSPECIFIED };
        struct color bg = { COLOR_UNSPECIFIED };
 
+       while (len > 0 && isspace(*ptr)) {
+               ptr++;
+               len--;
+       }
+
        if (!len)
                return -1;
 
-       if (!strncasecmp(value, "reset", len)) {
+       if (!strncasecmp(ptr, "reset", len)) {
                xsnprintf(dst, end - dst, GIT_COLOR_RESET);
                return 0;
        }