Skip to content

SDL_mixer_metadata_tags.c:parse_id3v1_ansi_string(): Fixed "always true" expression #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2025

Conversation

Sackzement
Copy link
Contributor

@Sackzement Sackzement commented Jul 26, 2025

The comparison i >= 0 is always true because i is an unsigned type.

[  6%] Building C object CMakeFiles/SDL3_mixer-shared.dir/src/SDL_mixer_metadata_tags.c.o
/path/to/SDL_mixer/src/SDL_mixer_metadata_tags.c: In functionparse_id3v1_ansi_string’:
/path/to/SDL_mixer/src/SDL_mixer_metadata_tags.c:99:37: warning: comparison of unsigned expression in ‘>= 0is always true [-Wtype-limits]
   99 |     for (size_t i = src_len - 1; (i >= 0) && (src_buffer[i] == ' '); i--) {
      |                                     ^~

This commit uses a do-while loop instead.

Might be a bit more "chatty". :)
4 lines vs 12 lines

@Sackzement Sackzement force-pushed the unsigned-always-true branch from 46f5a5b to f8d8549 Compare July 26, 2025 13:14
@Sackzement
Copy link
Contributor Author

Totally forgot the break;for the second condition. It's fixed now.

@slouken slouken merged commit 59a2f77 into libsdl-org:main Jul 26, 2025
5 checks passed
@slouken
Copy link
Collaborator

slouken commented Jul 26, 2025

Merged, thanks!

@Sackzement Sackzement deleted the unsigned-always-true branch July 26, 2025 15:22
@sezero
Copy link
Contributor

sezero commented Jul 26, 2025

And why is the loop iterator in there is a size_t instead of a plain signed int??

@Sackzement
Copy link
Contributor Author

And why is the loop iterator in there is a size_t instead of a plain signed int??

src_len is also size_t. The loop iterator just uses the same type as what is passed to the function.
My guess is because the buffer can be very large which int wouldn't be able to index.

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.

3 participants