summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2023-05-18 23:52:54 +0200
committerAlbert Cervin <albert@acervin.com>2023-05-18 23:52:54 +0200
commita4d17ddb8e7d23ccca13132f4d88cfc5f5730b76 (patch)
tree3797d4ebafc7af128020e37678815c0f8c00072f /src
parent74f4ec2a181a28a3b787cee0dc8e9ea74f50a8f8 (diff)
downloaddged-a4d17ddb8e7d23ccca13132f4d88cfc5f5730b76.tar.gz
dged-a4d17ddb8e7d23ccca13132f4d88cfc5f5730b76.tar.xz
dged-a4d17ddb8e7d23ccca13132f4d88cfc5f5730b76.zip
Fix too small index in keyboard code
The buffer _can_ be bigger than 255
Diffstat (limited to 'src')
-rw-r--r--src/dged/keyboard.c9
-rw-r--r--src/dged/keyboard.h4
2 files changed, 10 insertions, 3 deletions
diff --git a/src/dged/keyboard.c b/src/dged/keyboard.c
index 4b142ee..63b7b6e 100644
--- a/src/dged/keyboard.c
+++ b/src/dged/keyboard.c
@@ -120,8 +120,15 @@ struct keyboard_update keyboard_update(struct keyboard *kbd,
nbytes += nread;
if (nbytes > 0) {
- upd.nbytes = nbytes;
upd.raw = frame_alloc(nbytes);
+
+ if (upd.raw == NULL) {
+ fprintf(stderr, "failed to allocate buffer of %d bytes\n", nbytes);
+ free(buf);
+ return upd;
+ }
+
+ upd.nbytes = nbytes;
memcpy(upd.raw, buf, nbytes);
upd.keys = frame_alloc(sizeof(struct key) * nbytes);
memset(upd.keys, 0, sizeof(struct key) * nbytes);
diff --git a/src/dged/keyboard.h b/src/dged/keyboard.h
index e602b69..e65563f 100644
--- a/src/dged/keyboard.h
+++ b/src/dged/keyboard.h
@@ -48,9 +48,9 @@ struct key {
/** Modifier keys pressed (or-ed together) */
uint8_t mod;
/** Index where this key press starts in the raw input buffer */
- uint8_t start;
+ uint32_t start;
/** Index where this key press ends in the raw input buffer */
- uint8_t end;
+ uint32_t end;
};
/**