aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-04-07 06:00:39 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-04-18 18:07:58 +0000
commit7fc3b1858652e7d1f910ca81cf501fe23516b40a (patch)
tree91c7bb1c2bcfc0d790ac2c1e8069df23747b8c08
parentosc: parse_rgb(): ensure ‘alpha’ has been initialized (diff)
osc: parse_legacy_color(): the alpha component is not a floating point number
When using the urxvt extension of the XParseColor format, the alpha component is not a floating point number, but a decimal number in the range 0-100.
-rw-r--r--osc.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/osc.c b/osc.c
index 99803236..0aa75247 100644
--- a/osc.c
+++ b/osc.c
@@ -268,19 +268,18 @@ parse_legacy_color(const char *string, uint32_t *color, bool *_have_alpha,
uint16_t alpha = 0xffff;
if (string[0] == '[') {
- /* e.g. \E]11;[0.5]#00ff00 */
+ /* e.g. \E]11;[50]#00ff00 */
const char *start = &string[1];
- const char *end = strchr(string, ']');
- if (end == NULL)
- return false;
- char *_end;
- double percent = strtod(start, &_end);
- if (_end != end)
+ errno = 0;
+ char *end;
+ unsigned long percent = strtoul(start, &end, 10);
+
+ if (errno != 0 || *end != ']')
return false;
have_alpha = true;
- alpha = 0xffff * percent;
+ alpha = (0xffff * min(percent, 100) + 50) / 100;
string = end + 1;
}