Skip to content

Avoid GCC -Warray-bounds false positive in VideoFrame.from_dlpack - #2468

Merged
WyattBlue merged 1 commit into
masterfrom
fix-dlpack-warning
Oct 24, 2026
Merged

WyattBlue merged 1 commit into
masterfrom
fix-dlpack-warning

Conversation

@WyattBlue

@WyattBlue WyattBlue commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Building with GCC (seen on the riscv64 job) gives five -Warray-bounds warnings in src/av/video/frame.c, all from one line in VideoFrame.from_dlpack:

if device_id not in (None, 0):

Cython compiles the None half of this as __Pyx_PyObject_CompareBoolNe_int_object(device_id, Py_None, Py_NE), an int-specialized helper with Py_None as the int operand. The helper only reads PyLong fields after PyLong_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. The None check becomes a pointer comparison, so Py_None never reaches the int helper.

Compiling frame.c with gcc-16 -O3 -Wall gave all five warnings before this change and none after. tests/test_dlpack.py passes.

The same check in _from_dlpack_planar compiles to the generic object comparison and doesn't warn, but it's rewritten the same way for consistency, and because is not None is a cheaper pointer check in Cython.

`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
WyattBlue merged commit 5cf584a into master Oct 24, 2026
9 checks passed
@WyattBlue
WyattBlue deleted the fix-dlpack-warning branch October 24, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant