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.
This commit is contained in:
Ville Juven 2022-11-23 11:26:08 +02:00 committed by Xiang Xiao
parent 52228fd222
commit 4781379ee2
2 changed files with 4 additions and 3 deletions

View File

@ -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);

View File

@ -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.