summaryrefslogtreecommitdiff
path: root/pkg/kbd/patch/0001-Avoid-pointer-arithmetic-on-void.patch
blob: 2b843e8d1eb7c3e87c91bb5566fd731904f6169a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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