Skip to content

pixels: truncate SDL_SetPaletteColors input array silently - #16334

Merged
slouken merged 1 commit into
libsdl-org:mainfrom
lyorig:main
Sep 21, 2026
Merged

slouken merged 1 commit into
libsdl-org:mainfrom
lyorig:main

Conversation

@lyorig

@lyorig lyorig commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the SDL project under the zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Makes SDL_SetPaletteColors return true even if the input array is too large, documenting the truncation behavior.

Description

This function currently has two failure conditions:

  1. The palette is invalid.
  2. The input array is too large.

Curiously, in the second condition, the colors that fit are still written, although false is returned. This seems somewhat confusing, and I'd suggest improving it in one of two ways:

  1. Don't return false when this truncation occurs, and document that the length is adjusted automatically.
  2. Keep the current behavior, and document that false doesn't necessarily mean that nothing happened.

This PR currently implements the former option (tests are passing), but I'd be happy to change it to the latter, since it is a somewhat opinionated change. I understand that the current behavior can help detect a size mismatch, since there is no public API for retrieving the size of an SDL_Palette. However, in either case, it's behavior that's worth documenting.

Existing Issue(s)

None.

@slouken
slouken merged commit e93ec0b into libsdl-org:main Sep 21, 2026
10 checks passed
@slouken

slouken commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Merged, thanks!

@slouken slouken added this to the 3.6.0 milestone Sep 21, 2026
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.

2 participants