Skip to content

NULL guard in _preview_write_image (fixes GCC 16 -Werror=nonnull)#20895

Merged
TurboGit merged 1 commit intodarktable-org:masterfrom
andriiryzhkov:fix_gcc16
Apr 28, 2026
Merged

NULL guard in _preview_write_image (fixes GCC 16 -Werror=nonnull)#20895
TurboGit merged 1 commit intodarktable-org:masterfrom
andriiryzhkov:fix_gcc16

Conversation

@andriiryzhkov
Copy link
Copy Markdown
Contributor

Add a NULL guard at the top of _preview_write_image() to fix the build under GCC 16+ with -Werror=nonnull.

Fixes #20894

Details

GCC 16's interprocedural NULL analysis follows function pointers and detects that dt_imageio_export() passes NULL for the in argument when the format mime is "x-copy" (imageio.c:1010-1014). Since _preview_write_image is registered as a write_image callback, GCC concludes that NULL can reach the memcpy call inside it. The diagnostic is technically correct: memcpy from a NULL source is undefined behaviour even when n is zero.

In practice the runtime path doesn't fire for the preview format, but the static analysis can't see that.

The fix is a one-line if(!in) return 1; at the top of the function – return non-zero so a future caller that does pass NULL gets a clear error rather than UB.

The bug has been latent since b49bf38062 (Oct 2022); only newer GCC versions (16+) catch it because of stricter NULL propagation across indirect calls.

@TurboGit TurboGit added this to the 5.6 milestone Apr 28, 2026
Copy link
Copy Markdown
Member

@TurboGit TurboGit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@TurboGit TurboGit added bugfix pull request fixing a bug scope: codebase making darktable source code easier to manage labels Apr 28, 2026
@TurboGit TurboGit merged commit 80da161 into darktable-org:master Apr 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix pull request fixing a bug scope: codebase making darktable source code easier to manage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure on GCC 16: -Werror=nonnull in _preview_write_image (imageio.c)

2 participants