From 4c745dab4c6925fa17714c2214ed5941e5cbf64d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 20 Feb 2025 20:24:28 +0100 Subject: Validate unmarshalled state + add man pages for (un)marshal functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libterminput_unmarshal_input.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'libterminput_unmarshal_input.c') diff --git a/libterminput_unmarshal_input.c b/libterminput_unmarshal_input.c index ef8606c..851d0be 100644 --- a/libterminput_unmarshal_input.c +++ b/libterminput_unmarshal_input.c @@ -15,16 +15,30 @@ libterminput_unmarshal_input(struct libterminput_unmarshaller *how, union libter if (how->load(how, &what->type, sizeof(what->type))) return -1; } - if (what->type == LIBTERMINPUT_KEYPRESS) + switch ((int)what->type) { + case LIBTERMINPUT_KEYPRESS: r = libterminput_unmarshal_keypress__(how, &what->keypress); - else if (what->type == LIBTERMINPUT_TEXT) + break; + case LIBTERMINPUT_TEXT: r = libterminput_unmarshal_text__(how, &what->text); - else if (what->type == LIBTERMINPUT_MOUSEEVENT) + break; + case LIBTERMINPUT_MOUSEEVENT: r = libterminput_unmarshal_mouseevent__(how, &what->mouseevent); - else if (what->type == LIBTERMINPUT_CURSOR_POSITION) + break; + case LIBTERMINPUT_CURSOR_POSITION: r = libterminput_unmarshal_position__(how, &what->position); - else + break; + case LIBTERMINPUT_NONE: + case LIBTERMINPUT_BRACKETED_PASTE_START: + case LIBTERMINPUT_BRACKETED_PASTE_END: + case LIBTERMINPUT_TERMINAL_IS_OK: + case LIBTERMINPUT_TERMINAL_IS_NOT_OK: r = 0; + break; + default: + errno = EINVAL; + return -1; + } what->type = type; return r; } -- cgit v1.2.3-70-g09d2