NULL guard in _preview_write_image (fixes GCC 16 -Werror=nonnull)#20895
Merged
TurboGit merged 1 commit intodarktable-org:masterfrom Apr 28, 2026
Merged
NULL guard in _preview_write_image (fixes GCC 16 -Werror=nonnull)#20895TurboGit merged 1 commit intodarktable-org:masterfrom
TurboGit merged 1 commit intodarktable-org:masterfrom
Conversation
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.
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()passesNULLfor theinargument when the format mime is"x-copy"(imageio.c:1010-1014). Since_preview_write_imageis registered as awrite_imagecallback, GCC concludes that NULL can reach thememcpycall inside it. The diagnostic is technically correct:memcpyfrom a NULL source is undefined behaviour even whennis 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.