From e10b362bdb3772bd0634607cfe4d5ef27515777b Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 28 Oct 2013 23:29:08 +0100 Subject: getch2: move global state to file scope variables Using static variables for mutable state inside functions is a bad idea, because it's not immediately obvious that it is what it is. --- osdep/getch2.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/osdep/getch2.c b/osdep/getch2.c index e1586dc2eb..13eb47bc29 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -340,6 +340,11 @@ void get_screen_size(void) { static unsigned char getch2_buf[BUF_LEN]; static int getch2_len = 0; static int getch2_pos = 0; +static enum { + STATE_INITIAL, + STATE_UTF8, +} state = STATE_INITIAL; +static int utf8_len = 0; static void walk_buf(unsigned int count) { if (!(count < BUF_LEN && count <= getch2_len)) @@ -365,12 +370,6 @@ bool getch2(struct input_ctx *input_ctx) return retval; getch2_len += retval; - static enum { - STATE_INITIAL = 0, - STATE_UTF8, - } state = STATE_INITIAL; - static int utf8_len = 0; - while (getch2_pos < getch2_len) { unsigned char c = getch2_buf[getch2_pos++]; -- cgit v1.2.3