Skip to content

Commit

Permalink
avoid null-pointer-subtraction error (#78)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nitzmahone committed May 23, 2024
1 parent d7f750b commit 39bdab2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/cffi/recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 39bdab2

Please sign in to comment.