(parse_256_or_true_color_name): pacify gcc-10.2.

Fix warnings:

lib/tty/color-internal.c: In function 'tty_color_get_index_by_name':
lib/tty/color-internal.c:156:19: warning: '[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
  156 |             i = (h[0] << 20) | (h[1] << 16) | (h[2] << 12) | (h[3] << 8) | (h[4] << 4) | h[5];
      |                  ~^~~
lib/tty/color-internal.c:156:34: warning: 'h[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
  156 |             i = (h[0] << 20) | (h[1] << 16) | (h[2] << 12) | (h[3] << 8) | (h[4] << 4) | h[5];
      |                                 ~^~~
lib/tty/color-internal.c:156:49: warning: 'h[2]' may be used uninitialized in this function [-Wmaybe-uninitialized]
  156 |             i = (h[0] << 20) | (h[1] << 16) | (h[2] << 12) | (h[3] << 8) | (h[4] << 4) | h[5];
      |                                                ~^~~

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-01-10 16:36:30 +03:00
parent 452074906a
commit f4b1c0a4d0

View File

@ -136,25 +136,26 @@ parse_256_or_true_color_name (const char *color_name)
if (color_name[0] == '#') if (color_name[0] == '#')
{ {
int len; int len;
int h[6];
color_name++; color_name++;
len = (int) strlen (color_name); len = (int) strlen (color_name);
if (len != 3 && len != 6) if (len == 3 || len == 6)
return -1;
for (i = 0; i < len; i++)
{ {
h[i] = parse_hex_digit (color_name[i]); int h[6];
if (h[i] == -1)
return -1;
}
if (i == 3) for (i = 0; i < len; i++)
i = (h[0] << 20) | (h[0] << 16) | (h[1] << 12) | (h[1] << 8) | (h[2] << 4) | h[2]; {
else h[i] = parse_hex_digit (color_name[i]);
i = (h[0] << 20) | (h[1] << 16) | (h[2] << 12) | (h[3] << 8) | (h[4] << 4) | h[5]; if (h[i] == -1)
return (1 << 24) | i; return -1;
}
if (i == 3)
i = (h[0] << 20) | (h[0] << 16) | (h[1] << 12) | (h[1] << 8) | (h[2] << 4) | h[2];
else
i = (h[0] << 20) | (h[1] << 16) | (h[2] << 12) | (h[3] << 8) | (h[4] << 4) | h[5];
return (1 << 24) | i;
}
} }
return -1; return -1;