Fixed an off-by-one error in ll_string functions

This commit is contained in:
Andrew Brooks 2018-01-27 22:07:51 +00:00
parent 6be9728865
commit f52314ae23
1 changed files with 4 additions and 2 deletions

View File

@ -52,6 +52,7 @@ main(int argc, char **argv)
if (barcode[0] == '\x00')
{
/* Newline is pressed twice. Ignore any 'empty' barcodes. */
fprintf(stderr, "Encountered empty barcode.\n");
continue;
}
if (zsock_send(zsock, "s", barcode) < 0)
@ -107,8 +108,9 @@ decode_next_event(int fd)
/*
* If we received a keypress event, decode the keycode responsible.
* An event value of 1 is a keypress.
*/
if (event.type == EV_KEY) {
if (event.type == EV_KEY && event.value == 1) {
switch (event.code) {
#define DECODE_KEY(key_name, decode_char) case (KEY_##key_name): return decode_char
DECODE_KEY(ENTER, '\n');
@ -240,7 +242,7 @@ ll_string_to_c_string(ll_string *l)
// Copy the rest of the linked list into the C-string.
for (int i = size; i > 0; i--)
{
c_string[i] = rest->character;
c_string[i - 1] = rest->character;
rest = rest->next;
}