From 7736629bc4c5efc286abae39ed23abf82f93c015 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 28 Sep 2017 08:20:53 +0530 Subject: [PATCH] Fix graphics id not going upto UINT32_MAX --- kitty/parser.c | 10 +++++----- kitty_tests/parser.py | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/kitty/parser.c b/kitty/parser.c index 98b245c01..8714ee015 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -11,13 +11,13 @@ #include // utils {{{ -static unsigned int pow10[10] = { - 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 +static unsigned long pow10[] = { + 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000 }; -static inline unsigned int +static inline uint32_t utoi(uint32_t *buf, unsigned int sz) { - unsigned int ans = 0; + unsigned long ans = 0; uint32_t *p = buf; // Ignore leading zeros while(sz > 0) { @@ -602,7 +602,7 @@ parse_graphics_code(Screen *screen, PyObject UNUSED *dump_callback) { #undef F #define READ_UINT \ - for (i = pos; i < MIN(screen->parser_buf_pos, pos + 7); i++) { \ + for (i = pos; i < MIN(screen->parser_buf_pos, pos + 10); i++) { \ if (screen->parser_buf[i] < '0' || screen->parser_buf[i] > '9') break; \ } \ if (i == pos) { REPORT_ERROR("Malformed graphics control block, expecting an integer value"); return; } \ diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index 852715c28..cf820cec2 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -218,6 +218,9 @@ class TestParser(BaseTest): s = self.create_screen() pb = partial(self.parse_bytes_dump, s) + uint32_max = 2**32 - 1 + t('i=%d' % uint32_max, id=uint32_max) + t('i=%d' % (uint32_max + 1), id=0) pb('\033_Gi=12\033\\', c(id=12)) t('a=t,t=d,s=100,z=-9', payload='X', action='t', transmission_type='d', data_width=100, z_index=-9, payload_sz=1) t('a=t,t=d,s=100,z=9', payload='payload', action='t', transmission_type='d', data_width=100, z_index=9, payload_sz=7)