summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2020-07-02 23:45:32 +0200
committerBoris Faure <billiob@gmail.com>2020-07-02 23:45:32 +0200
commitc2dd1815c8873690c249545c64cf288359b40afb (patch)
treeb4b2f4399547333e5d5c4ee582d275bef2956df1
parentac9a92480b24d76ad9ecdd6dda50b7bbc741dfef (diff)
termptyesc: avoid issues with cast from double
+ no buffer overflow
-rw-r--r--src/bin/termptyesc.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 76e0991..ea3e4df 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -3771,7 +3771,7 @@ _xterm_parse_intensity(Eina_Unicode *p, unsigned char *c, int len)
3771 char *endptr_double; 3771 char *endptr_double;
3772 double d; 3772 double d;
3773 3773
3774 while (l < 64 && len && p[0] && p[0] != '/' && p[0] != '\007' && p[0] < 128) 3774 while (l < 63 && len && p[0] && p[0] != '/' && p[0] != '\007' && p[0] < 128)
3775 { 3775 {
3776 buf[l++] = p[0]; 3776 buf[l++] = p[0];
3777 len--; 3777 len--;
@@ -3785,7 +3785,11 @@ _xterm_parse_intensity(Eina_Unicode *p, unsigned char *c, int len)
3785 if (endptr_double == buf || d < 0 || d > 1.0 || isnan(d)) 3785 if (endptr_double == buf || d < 0 || d > 1.0 || isnan(d))
3786 return -1; 3786 return -1;
3787 3787
3788 *c = d * 255.0; 3788 d *= 255.0;
3789 if (d > 255.0)
3790 *c = 255;
3791 else
3792 *c = round(d);
3789 return endptr_double - buf; 3793 return endptr_double - buf;
3790} 3794}
3791 3795