From 4781379ee20bb74f031be61fb72d21121e7c7328 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Wed, 23 Nov 2022 11:26:08 +0200 Subject: [PATCH] obstack/obstack_free: Fix incorrect usage of void* for arithmetics Using void* for arithmetics is a GCC extension, and thus should not be used for portable code. --- libs/libc/obstack/lib_obstack_finish.c | 4 ++-- libs/libc/obstack/lib_obstack_free.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/libc/obstack/lib_obstack_finish.c b/libs/libc/obstack/lib_obstack_finish.c index 6c5fbcfc56..5cf1595b5a 100644 --- a/libs/libc/obstack/lib_obstack_finish.c +++ b/libs/libc/obstack/lib_obstack_finish.c @@ -66,10 +66,10 @@ FAR void *obstack_finish(FAR struct obstack *h) { chsize = h->next_free - (FAR char *)h->chunk; h->chunk = lib_obstack_realloc(h->chunk, chsize); - h->chunk->limit = (FAR void *)h->chunk + chsize; + h->chunk->limit = (FAR char *)h->chunk + chsize; h->object_base = h->chunk->limit; h->next_free = h->chunk->limit; - return (FAR void *)h->chunk + sizeof(struct _obstack_chunk); + return (FAR char *)h->chunk + sizeof(struct _obstack_chunk); } return obstack_finish_norealloc(h); diff --git a/libs/libc/obstack/lib_obstack_free.c b/libs/libc/obstack/lib_obstack_free.c index 460e27f054..6d5437de00 100644 --- a/libs/libc/obstack/lib_obstack_free.c +++ b/libs/libc/obstack/lib_obstack_free.c @@ -51,7 +51,8 @@ void obstack_free(FAR struct obstack *h, FAR void *object) while (h->chunk) { - if (object >= (FAR void *)&h->chunk + sizeof(struct _obstack_chunk) + if (object >= + (FAR void *)((FAR char *)&h->chunk + sizeof(struct _obstack_chunk)) && object < (FAR void *)h->chunk->limit) { /* The object is in this chunk so just move object base.