summaryrefslogtreecommitdiff
path: root/src/fastcsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fastcsi.c')
-rw-r--r--src/fastcsi.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/fastcsi.c b/src/fastcsi.c
index 416e3dc..dfd2dba 100644
--- a/src/fastcsi.c
+++ b/src/fastcsi.c
@@ -91,17 +91,40 @@ static inline const char *parse_color_sequence(const char *p, const char *end, u
static const char *parse_256color(const char *p, const char *end, uint32_t *color)
{
const char *q = p + 2;
- unsigned v = 0;
- int nd = 0;
- while (q < end && (unsigned char)(*q - '0') <= 9) {
- v = v * 10 + (unsigned char)(*q++ - '0');
- if (++nd > 3)
- return NULL;
+ if (q >= end)
+ return NULL;
+ unsigned char d0 = (unsigned char)(*q - '0');
+ if (d0 > 9)
+ return NULL;
+ q++;
+ if (q < end && *q == 'm') {
+ *color = term_color_index(d0);
+ return q + 1;
+ }
+ if (q >= end)
+ return NULL;
+ unsigned char d1 = (unsigned char)(*q - '0');
+ if (d1 > 9)
+ return NULL;
+ q++;
+ if (q < end && *q == 'm') {
+ *color = term_color_index(d0 * 10 + d1);
+ return q + 1;
}
- if (!nd || q >= end || *q != 'm' || v > 255)
+ if (q >= end)
+ return NULL;
+ unsigned char d2 = (unsigned char)(*q - '0');
+ if (d2 > 9)
return NULL;
- *color = term_color_index(v);
- return q + 1;
+ q++;
+ if (q < end && *q == 'm') {
+ unsigned v = d0 * 100 + d1 * 10 + d2;
+ if (v <= 255) {
+ *color = term_color_index(v);
+ return q + 1;
+ }
+ }
+ return NULL;
}
TERM_NOINLINE