lib/colors: assert rathen than overflow [-Wnull-dereference]
lib/colors.c: In function 'colors_read_schemes': lib/colors.c:412:7: warning: potential null pointer dereference [-Wnull-dereference] Reported-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
bd2aece45e
commit
ab7093775f
|
@ -342,6 +342,7 @@ static char *colors_get_homedir(char *buf, size_t bufsz)
|
|||
static int cn_sequence(const char *str, char **seq)
|
||||
{
|
||||
char *in, *out;
|
||||
int len;
|
||||
|
||||
if (!str)
|
||||
return -EINVAL;
|
||||
|
@ -357,7 +358,7 @@ static int cn_sequence(const char *str, char **seq)
|
|||
}
|
||||
|
||||
/* convert xx;yy sequences to "\033[xx;yy" */
|
||||
if (asprintf(seq, "\033[%sm", str) < 1)
|
||||
if ((len = asprintf(seq, "\033[%sm", str)) < 1)
|
||||
return -ENOMEM;
|
||||
|
||||
for (in = *seq, out = *seq; in && *in; in++) {
|
||||
|
@ -409,6 +410,8 @@ static int cn_sequence(const char *str, char **seq)
|
|||
}
|
||||
in++;
|
||||
}
|
||||
|
||||
assert ((out - *seq) <= len);
|
||||
*out = '\0';
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue