From 39bdab23615a83c1001ed822f974ae52020201ba Mon Sep 17 00:00:00 2001 From: Matt Davis <6775756+nitzmahone@users.noreply.github.com> Date: Thu, 23 May 2024 12:54:57 -0700 Subject: [PATCH] avoid null-pointer-subtraction error (#78) Newer compilers generate warnings/errors about null pointer subtractions being an undefined behavior. Use matching non-zero offsets (as suggested by arigo) to avoid the error. --- src/cffi/recompiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cffi/recompiler.py b/src/cffi/recompiler.py index 4167bc05..ac6c163e 100644 --- a/src/cffi/recompiler.py +++ b/src/cffi/recompiler.py @@ -953,7 +953,7 @@ def _struct_ctx(self, tp, cname, approxname, named_ptr=None): if cname is None or fbitsize >= 0: offset = '(size_t)-1' elif named_ptr is not None: - offset = '((char *)&((%s)0)->%s) - (char *)0' % ( + offset = '((char *)&((%s)4096)->%s) - (char *)4096' % ( named_ptr.name, fldname) else: offset = 'offsetof(%s, %s)' % (tp.get_c_name(''), fldname)