termptyesc: avoid issues with cast from double
+ no buffer overflow
This commit is contained in:
parent
ac9a92480b
commit
c2dd1815c8
|
@ -3771,7 +3771,7 @@ _xterm_parse_intensity(Eina_Unicode *p, unsigned char *c, int len)
|
||||||
char *endptr_double;
|
char *endptr_double;
|
||||||
double d;
|
double d;
|
||||||
|
|
||||||
while (l < 64 && len && p[0] && p[0] != '/' && p[0] != '\007' && p[0] < 128)
|
while (l < 63 && len && p[0] && p[0] != '/' && p[0] != '\007' && p[0] < 128)
|
||||||
{
|
{
|
||||||
buf[l++] = p[0];
|
buf[l++] = p[0];
|
||||||
len--;
|
len--;
|
||||||
|
@ -3785,7 +3785,11 @@ _xterm_parse_intensity(Eina_Unicode *p, unsigned char *c, int len)
|
||||||
if (endptr_double == buf || d < 0 || d > 1.0 || isnan(d))
|
if (endptr_double == buf || d < 0 || d > 1.0 || isnan(d))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*c = d * 255.0;
|
d *= 255.0;
|
||||||
|
if (d > 255.0)
|
||||||
|
*c = 255;
|
||||||
|
else
|
||||||
|
*c = round(d);
|
||||||
return endptr_double - buf;
|
return endptr_double - buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue