From 79bd13b1a56746d3a848444b5d95bb1739e3c3e2 Mon Sep 17 00:00:00 2001
From: Diomidis Spinellis <dds@aueb.gr>
Date: Fri, 1 Nov 2019 22:32:17 +0200
Subject: [PATCH 1/4] Include required header file for fd_set

---
 hid.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hid.c b/hid.c
index 42829ee..cf07c9b 100644
--- a/hid.c
+++ b/hid.c
@@ -17,6 +17,7 @@
  * Author: Thibault Kummer <bob@coldsource.net>
  */
 
+#include <sys/select.h>
 #include <hid.h>
 #include <log.h>
 #include <fcntl.h>

From 53b4b1f8570510bd158676957469b2fa05088218 Mon Sep 17 00:00:00 2001
From: Diomidis Spinellis <dds@aueb.gr>
Date: Fri, 1 Nov 2019 22:37:12 +0200
Subject: [PATCH 2/4] Fix clash with built-in log function

---
 include/log.h |  4 ++--
 log.cpp       | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/log.h b/include/log.h
index 39c58e4..3358e74 100644
--- a/include/log.h
+++ b/include/log.h
@@ -33,8 +33,8 @@ typedef enum LogLevel {
 
 extern int currentLogLevel;
 
-void log(LogLevel severity, const char* fmt, va_list args);
-//void log(LogLevel severity, const char* fmt, ...);
+void logmsg(LogLevel severity, const char* fmt, va_list args);
+//void logmsg(LogLevel severity, const char* fmt, ...);
 
 void info(const char* fmt, ...);
 void warn(const char* fmt, ...);
diff --git a/log.cpp b/log.cpp
index 8325447..a834abc 100644
--- a/log.cpp
+++ b/log.cpp
@@ -28,18 +28,18 @@ const char* headers[] = {
 	"ERRO",
 };
 
-void log(LogLevel severity, const char* fmt, va_list args) {
+void logmsg(LogLevel severity, const char* fmt, va_list args) {
 	if (severity < currentLogLevel) {
 		vfprintf(stderr, fmt, args);
 		putc('\n', stderr);
 	}
 }
 
-void log(LogLevel severity, const char* fmt, ...)
+void logmsg(LogLevel severity, const char* fmt, ...)
 {
 	va_list args;
 	va_start(args, fmt);
-	log(severity, fmt, args);
+	logmsg(severity, fmt, args);
 	va_end(args);
 
 }
@@ -48,7 +48,7 @@ void info(const char* fmt, ...)
 {
 	va_list args;
 	va_start(args, fmt);
-	log(LOG_INFO, fmt, args);
+	logmsg(LOG_INFO, fmt, args);
 	va_end(args);
 }
 
@@ -56,7 +56,7 @@ void warn(const char* fmt, ...)
 {
 	va_list args;
 	va_start(args, fmt);
-	log(LOG_WARN, fmt, args);
+	logmsg(LOG_WARN, fmt, args);
 	va_end(args);
 }
 
@@ -64,7 +64,7 @@ void error(const char* fmt, ...)
 {
 	va_list args;
 	va_start(args, fmt);
-	log(LOG_ERROR, fmt, args);
+	logmsg(LOG_ERROR, fmt, args);
 	va_end(args);
 }
 

From f6ca23e74bf493e379ca63b0be1a20ee3a21572d Mon Sep 17 00:00:00 2001
From: Diomidis Spinellis <dds@aueb.gr>
Date: Fri, 1 Nov 2019 22:38:07 +0200
Subject: [PATCH 3/4] Add header required for strcmp

---
 hid.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hid.c b/hid.c
index cf07c9b..563b548 100644
--- a/hid.c
+++ b/hid.c
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <stdio.h>
+#include <string.h>
 
 #define SYSFS_HIDRAW_CLASS_PATH "/sys/class/hidraw"
 

From a38e46cf4907ef47b86bd039c430b2abd1af5712 Mon Sep 17 00:00:00 2001
From: Diomidis Spinellis <dds@aueb.gr>
Date: Fri, 1 Nov 2019 23:17:38 +0200
Subject: [PATCH 4/4] Fix key code reading

- Rewrite statement with undefined behavior
- Show unknown keys
---
 MapReader.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/MapReader.cpp b/MapReader.cpp
index aa86f32..02e9715 100644
--- a/MapReader.cpp
+++ b/MapReader.cpp
@@ -105,8 +105,10 @@ void MapReader::LoadMap(const char *filename,EventMapping *map)
 			
 			i = 0;
 
-			while(i<KEY_NAME_MAXLENGTH && ptr[i]!='\0' && ptr[i]!='\n' && (!isspace(ptr[i])))
-				key_name[i] = ptr[i++];
+			while(i<KEY_NAME_MAXLENGTH && ptr[i]!='\0' && ptr[i]!='\n' && (!isspace(ptr[i]))) {
+				key_name[i] = ptr[i];
+				i++;
+			}
 			
 			if(i==KEY_NAME_MAXLENGTH)
 			{
@@ -150,7 +152,7 @@ void MapReader::LoadMap(const char *filename,EventMapping *map)
 				key = Keys::Lookup(key_name);
 				if(key<0)
 				{
-					sprintf(error,"Unknown key name at line %d",line);
+					sprintf(error,"Unknown key name [%s] at line %d", key_name, line);
 					throw Exception("MapReader",error);
 				}
 			}
