Repository navigation
Avoid GCC -Warray-bounds false positive in VideoFrame.from_dlpack - #2468
Merged
Merged
Conversation
WyattBlue
force-pushed
the
fix-dlpack-warning
branch
from
October 24, 2026 17:15
b55ff48 to
7ee54c7
Compare
`device_id not in (None, 0)` made Cython pass `Py_None` to an int comparison helper. The helper's `PyLong_CheckExact` guard makes this safe, but GCC can't evaluate it at compile time and warned about reads past `_Py_NoneStruct`. Check `is not None` first instead, here and in the same check in `_from_dlpack_planar`.
WyattBlue
force-pushed
the
fix-dlpack-warning
branch
from
October 24, 2026 17:15
7ee54c7 to
77f0460
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Building with GCC (seen on the riscv64 job) gives five
-Warray-boundswarnings insrc/av/video/frame.c, all from one line inVideoFrame.from_dlpack:Cython compiles the
Nonehalf of this as__Pyx_PyObject_CompareBoolNe_int_object(device_id, Py_None, Py_NE), an int-specialized helper withPy_Noneas the int operand. The helper only readsPyLongfields afterPyLong_CheckExact(op2)passes, so this is safe at runtime. GCC can't evaluate that check at compile time, though, and warns about reads at offsets 24 and 28 into the 16-byte_Py_NoneStruct.This rewrites it as
device_id is not None and device_id != 0, which behaves the same. TheNonecheck becomes a pointer comparison, soPy_Nonenever reaches the int helper.Compiling
frame.cwithgcc-16 -O3 -Wallgave all five warnings before this change and none after.tests/test_dlpack.pypasses.The same check in
_from_dlpack_planarcompiles to the generic object comparison and doesn't warn, but it's rewritten the same way for consistency, and becauseis not Noneis a cheaper pointer check in Cython.