[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/2] obstack: avoid undefined pointer comparison
From: |
Bruno Haible |
Subject: |
Re: [PATCH 2/2] obstack: avoid undefined pointer comparison |
Date: |
Mon, 12 May 2025 13:22:57 +0200 |
Paul Eggert wrote on 2025-05-07:
> * lib/obstack.in.h (_OBSTACK_CPTR): New macro.
> (obstack_free): Use it instead of comparing pointers directly,
> when the pointers might not point into the same object.
Thanks. That is an important fix, now that compilers start to turn
invalid pointer arithmetic into unexpected code modifications, e.g.
<https://gitlab.com/gnu-clisp/clisp/-/merge_requests/12>.
However, this patch produces a compilation error on MSVC, in every
invocation of obstack_free(), such as
D:\a\ci-testdir-check\ci-testdir-check\testdir-all\gllib\bitset\table.c(1167):
error C2065: 'OBSTACK_CPTR': undeclared identifier
D:\a\ci-testdir-check\ci-testdir-check\testdir-all\gllib\bitset\table.c(1167):
error C2064: term does not evaluate to a function taking 0 arguments
make[4]: *** [Makefile:12048: bitset/table.obj] Error 2
This patch fixes it.
2025-05-12 Bruno Haible <bruno@clisp.org>
obstack: Fix compilation error on MSVC (regression 2025-05-07).
* lib/obstack.in.h (obstack_free): Fix typo.
diff --git a/lib/obstack.in.h b/lib/obstack.in.h
index 698b6b37a7..91a5e444c9 100644
--- a/lib/obstack.in.h
+++ b/lib/obstack.in.h
@@ -590,7 +590,7 @@ extern int obstack_exit_failure;
# define obstack_free(h, obj) \
((h)->temp.tempptr = (void *) (obj), \
- (((_OBSTACK_CPTR) (h)->chunk < (OBSTACK_CPTR) (h)->temp.tempptr \
+ (((_OBSTACK_CPTR) (h)->chunk < (_OBSTACK_CPTR) (h)->temp.tempptr \
&& (_OBSTACK_CPTR) (h)->temp.tempptr < (_OBSTACK_CPTR) (h)->chunk_limit) \
? (void) ((h)->next_free = (h)->object_base = (char *) (h)->temp.tempptr) \
: __obstack_free (h, (h)->temp.tempptr)))