Code

Fix uninitialized variable in string_expand_length
[tig.git] / tig.c
diff --git a/tig.c b/tig.c
index e25ba686ea8b26ebc8f21b2e95cdfa2bc44c97ad..97794b0e6e0d85793b678537aff32e65902c5fe7 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -193,7 +193,7 @@ string_expand_length(const char *line, int tabsize)
 {
        size_t size, pos;
 
-       for (pos = 0; line[pos]; pos++) {
+       for (size = pos = 0; line[pos]; pos++) {
                if (line[pos] == '\t' && tabsize > 0)
                        size += tabsize - (size % tabsize);
                else
@@ -1388,9 +1388,28 @@ static struct enum_map attr_map[] = {
        ATTR_MAP(UNDERLINE),
 };
 
-#define set_color(color, name)         map_enum(color, color_map, name)
 #define set_attribute(attr, name)      map_enum(attr, attr_map, name)
 
+static int
+parse_int(int *opt, const char *arg, int min, int max)
+{
+       int value = atoi(arg);
+
+       if (min <= value && value <= max)
+               *opt = value;
+       return OK;
+}
+
+static bool
+set_color(int *color, const char *name)
+{
+       if (map_enum(color, color_map, name))
+               return TRUE;
+       if (!prefixcmp(name, "color"))
+               return parse_int(color, name + 5, 0, 255) == OK;
+       return FALSE;
+}
+
 static int   config_lineno;
 static bool  config_errors;
 static const char *config_msg;
@@ -1443,16 +1462,6 @@ static int parse_bool(bool *opt, const char *arg)
        return OK;
 }
 
-static int
-parse_int(int *opt, const char *arg, int min, int max)
-{
-       int value = atoi(arg);
-
-       if (min <= value && value <= max)
-               *opt = value;
-       return OK;
-}
-
 static int
 parse_string(char *opt, const char *arg, size_t optsize)
 {