summaryrefslogtreecommitdiff
path: root/pkg/kbd/patch/0001-Avoid-pointer-arithmetic-on-void.patch
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/kbd/patch/0001-Avoid-pointer-arithmetic-on-void.patch')
-rw-r--r--pkg/kbd/patch/0001-Avoid-pointer-arithmetic-on-void.patch61
1 files changed, 61 insertions, 0 deletions
diff --git a/pkg/kbd/patch/0001-Avoid-pointer-arithmetic-on-void.patch b/pkg/kbd/patch/0001-Avoid-pointer-arithmetic-on-void.patch
new file mode 100644
index 00000000..2b843e8d
--- /dev/null
+++ b/pkg/kbd/patch/0001-Avoid-pointer-arithmetic-on-void.patch
@@ -0,0 +1,61 @@
+From 36ab4890a83ec2347dc1955dd8cc40095e497890 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Tue, 12 Mar 2019 16:45:54 -0700
+Subject: [PATCH] Avoid pointer arithmetic on `void *`
+
+Standard C requires that the pointer operand to the + operator be to a
+complete object type[0], so use a `char *` instead.
+
+[0] http://port70.net/~nsz/c/c11/n1570.html#6.5.6p2
+---
+ src/libkeymap/array.c | 6 +++---
+ src/libkeymap/keymap/array.h | 2 +-
+ 2 files changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/src/libkeymap/array.c b/src/libkeymap/array.c
+index 076c1de..ec175df 100644
+--- a/src/libkeymap/array.c
++++ b/src/libkeymap/array.c
+@@ -54,7 +54,7 @@ int lk_array_exists(struct lk_array *a, unsigned int i)
+ return 0;
+ }
+
+- s = (char *)(a->array + (a->memb * i));
++ s = a->array + (a->memb * i);
+
+ for (k = 0; k < a->memb; k++) {
+ if (s[k] != 0)
+@@ -80,7 +80,7 @@ lk_array_get_ptr(struct lk_array *a, unsigned int i)
+ if (!a || i >= a->total) {
+ return NULL;
+ }
+- ptr = a->array;
++ ptr = (void **)a->array;
+ return *(ptr + i);
+ }
+
+@@ -91,7 +91,7 @@ array_resize(struct lk_array *a, unsigned int i)
+ return -EINVAL;
+
+ if (i >= a->total) {
+- void *tmp = realloc(a->array, a->memb * (i + 1));
++ char *tmp = realloc(a->array, a->memb * (i + 1));
+ if (!tmp)
+ return -ENOMEM;
+
+diff --git a/src/libkeymap/keymap/array.h b/src/libkeymap/keymap/array.h
+index 9894af1..caac6fb 100644
+--- a/src/libkeymap/keymap/array.h
++++ b/src/libkeymap/keymap/array.h
+@@ -6,7 +6,7 @@
+ * @details The array is designed to store an arbitrary number of similar items.
+ */
+ struct lk_array {
+- void *array; /**< Data pointer. */
++ char *array; /**< Data pointer. */
+ size_t memb; /**< One element size. */
+ size_t count; /**< Number of elements. */
+ size_t total; /**< Total number of allocated elements. */
+--
+2.20.1
+