From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mforney-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=wGuw8B0bn6k9+uQ5Cpr2sCvsMr+JHD/qGAXNhFziO0I=; b=ASzur9g/uUtxtTPfQfgzGepOV8J2y6G836LMAlX5LqeoeN9Yx+QmQdc4aTZaeCJZIs Sc6rcbBDdymqavzjIq1x85eY6pA/9xmQGLyOSFEhG1m/Tm0DMK6OjTbc1395hb5xAXnQ o9N2U79KZrADVtdfIXZ5+4EbSUtuu5TnKMdmsZelkI72tM5xIcsNofYFD8U1NKZGXAs4 wWollxGEJ9VJ8gumqNhQE1IuI9lh0QIMykr3Ykgnd36rmcbYsTNX7sqeVeTjOg19P0gJ qBiDJ6D164Ym884ncV7y1/v3LrxH9Isa99qvjr+5P9KNv26+LJhtX5LO3MHG1aPBNE+k QU7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=wGuw8B0bn6k9+uQ5Cpr2sCvsMr+JHD/qGAXNhFziO0I=; b=VXHUILfN5BgL/7DLsUPEmwlXxfvlAsL3OYe52wvOG0rjSnr+e3fi9gkr+qMqF4YKEA X5L7lR6XUa6i300Gs8uJ4I79Xmn2pc6h/KvggRcE32G/FY2oj77+CHMIYs/idkWEluvV lrmIQzS8CpJcBtYKxORCt+C4uQYUfcccA8Dh2TwhChZv49Cd5uMC+L3JQTXWByRGsTfy tlFaqaWlhyUBLnKAKXIk7f6JzWcSt45ogka8KvV3bY82UylLsHTwEDrfAE6hQ6k8zjGp 9ZTEI6SV9Wd5xdc3YWNh92l/TFgXZZyLExtY+PSL4myErCZkps/ocPGpf5BAlQAznT0f cYSQ== X-Gm-Message-State: APjAAAVE5uPE0DKxUyi5vevKkuu9uMBCBamM68O45YqauQhToI2HybBB 02wgeNnITwFhRASpM5sJRKaX+4zgYOsjog== X-Google-Smtp-Source: APXvYqxwSP3inVOMgAVYsOucF7RWuvaw5r7sHFEyb/BC4vrMHNWNP5FiSEHsSMGW4httDXnNQwkJmQ== X-Received: by 2002:a17:902:7043:: with SMTP id h3mr1912751plt.10.1561604840307; Wed, 26 Jun 2019 20:07:20 -0700 (PDT) From: Michael Forney To: kbd@lists.altlinux.org Date: Wed, 26 Jun 2019 20:07:19 -0700 Message-Id: <20190627030719.4116-1-mforney@mforney.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [kbd] [PATCH] libkeymap: Avoid pointer arithmetic on `void *` X-BeenThere: kbd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Linux console tools development discussion List-Id: Linux console tools development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jun 2019 03:07:25 -0000 Archived-At: List-Archive: ISO C requires that the pointer operand to the binary + operator be to a complete object type[0]. Since we are working with byte sizes, use `char *` instead. [0] http://port70.net/~nsz/c/c11/n1570.html#6.5.6p2 Signed-off-by: Michael Forney --- Another option with less casting is to change the type of the `array` member of `struct lk_array` from `void *` to `char *`. Let me know if you would prefer this approach: https://github.com/michaelforney/kbd/commit/5554deb1df4263d5d6b782a484dbb78b1b3ad569 configure.ac | 1 + src/libkeymap/array.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index f2389b2..991d95e 100644 --- a/configure.ac +++ b/configure.ac @@ -88,6 +88,7 @@ CC_CHECK_CFLAGS_APPEND([\ -Wmissing-format-attribute \ -Wmissing-noreturn \ -Wmissing-prototypes \ + -Wpointer-arith \ -Wredundant-decls \ -Wshadow \ -Wstrict-prototypes \ diff --git a/src/libkeymap/array.c b/src/libkeymap/array.c index 0583c13..b2fb6b6 100644 --- a/src/libkeymap/array.c +++ b/src/libkeymap/array.c @@ -67,7 +67,7 @@ lk_array_exists(struct lk_array *a, ssize_t i) return 0; } - s = (char *)(a->array + (a->memb * i)); + s = (char *) a->array + (a->memb * i); for (k = 0; k < a->memb; k++) { if (s[k] != 0) @@ -84,7 +84,7 @@ lk_array_get(struct lk_array *a, ssize_t i) errno = EINVAL; return NULL; } - return a->array + (a->memb * i); + return (char *) a->array + (a->memb * i); } void * @@ -114,7 +114,7 @@ array_resize(struct lk_array *a, ssize_t i) return -ENOMEM; } - memset(tmp + (a->memb * a->total), 0, (size_t) (a->memb * (i + 1 - a->total))); + memset((char *) tmp + (a->memb * a->total), 0, (size_t) (a->memb * (i + 1 - a->total))); a->array = tmp; a->total = i + 1; @@ -130,7 +130,7 @@ lk_array_set(struct lk_array *a, ssize_t i, const void *e) if (ret < 0) return ret; - memcpy(a->array + (a->memb * i), e, (size_t) a->memb); + memcpy((char *) a->array + (a->memb * i), e, (size_t) a->memb); a->count++; return 0; @@ -145,7 +145,7 @@ lk_array_unset(struct lk_array *a, ssize_t i) } if (lk_array_exists(a, i)) { - memset(a->array + (a->memb * i), 0, (size_t) a->memb); + memset((char *) a->array + (a->memb * i), 0, (size_t) a->memb); a->count--; } @@ -160,7 +160,7 @@ lk_array_append(struct lk_array *a, const void *e) if (ret < 0) return ret; - memcpy(a->array + (a->memb * a->count), e, (size_t) a->memb); + memcpy((char *) a->array + (a->memb * a->count), e, (size_t) a->memb); a->count++; return 0; -- 2.20.1