We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4865 - A small patch with several warning fixes, made in MixerX fork
Summary: A small patch with several warning fixes, made in MixerX fork
Status: RESOLVED FIXED
Alias: None
Product: SDL_mixer
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-17 17:32 UTC by Vitaly Novichkov
Modified: 2019-11-18 10:25 UTC (History)
1 user (show)

See Also:


Attachments
A set of warning fixes made in MixerX fork (36.36 KB, patch)
2019-11-17 17:32 UTC, Vitaly Novichkov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vitaly Novichkov 2019-11-17 17:32:18 UTC
Created attachment 4057 [details]
A set of warning fixes made in MixerX fork

There are several warning fixes made in MixerX fork many years ago and I would to backport them into mainstream SDL Mixer.
Comment 1 Ozkan Sezer 2019-11-17 20:10:29 UTC
RE: Title:  not so small a patch..

* effect_position.c, effect_stereoreverse.c:  For changes like:
-   len % sizeof (Uint32) != 0
+   (size_t)len % sizeof (Uint32) != 0

... it would be easier to do:
-   len % sizeof (Uint32) != 0
+   len % (int)sizeof(Uint32) != 0

... provided that len is int type (they all are int type, AFAICS.)
What do you think?

OTOH, effect_position.c line #1520 change is Ok.


* load_voc.c:
- sblen = ((bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16));
+ sblen = (Uint32)((bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16));

I _think_ it would be more correct doing like the following?
  sblen = (Uint32)(bits24[0]) | ((Uint32)bits24[1] << 8) | ((Uint32)bits24[2] << 16);

Same for music_mad.c changes of the like.


* load_voc.c, voc_read():
The procedure doesn't return negative. So, instead of casting done
to (int), changing voc_read to return 'unsigned int' is better?


Didn't look at the rest (tired.)
Comment 2 Vitaly Novichkov 2019-11-17 21:52:36 UTC
(In reply to Ozkan Sezer from comment #1)
> 
> * load_voc.c:
> - sblen = ((bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16));
> + sblen = (Uint32)((bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16));
> 
> I _think_ it would be more correct doing like the following?
>   sblen = (Uint32)(bits24[0]) | ((Uint32)bits24[1] << 8) |
> ((Uint32)bits24[2] << 16);
> 
> Same for music_mad.c changes of the like.

I think, yes, until it will produce warnings on some compilers, otherwuse, give next:
```
sblen = (Uint32)((Uint32)(bits24[0]) | ((Uint32)bits24[1] << 8) |
> ((Uint32)bits24[2] << 16));
```

> 
> 
> * load_voc.c, voc_read():
> The procedure doesn't return negative. So, instead of casting done
> to (int), changing voc_read to return 'unsigned int' is better?
> 
> 
> Didn't look at the rest (tired.)

Yeah, if it never returns a negative value, it should return Uint32 as the "done" value without casting it into an int.
Comment 3 Sam Lantinga 2019-11-18 01:41:31 UTC
This has been added, thanks!
https://hg.libsdl.org/SDL_mixer/rev/9781cbae03a2
Comment 4 Ozkan Sezer 2019-11-18 04:52:37 UTC
This introduced a build breakage, fixed here:
https://hg.libsdl.org/SDL_mixer/rev/5b7c09d1e108

This would have needed more reviewing / testing,
I guess.
Comment 5 Ozkan Sezer 2019-11-18 07:43:03 UTC
I pushed some cleanups, still not fully happy but whatever.

About the newly added Mix_strtok_safe(): is it truly needed?
Does Mix_EachSoundFont() need reentrancy??

About the new MIX_UNUSED macro: it has multiple definitions
in many places. Is there a sane place to put it so that every
module can see it?
Comment 6 Vitaly Novichkov 2019-11-18 08:04:55 UTC
> https://hg.libsdl.org/SDL_mixer/rev/7846c39b6154
Whops! Yeah, this thing should be in part of this: https://bugzilla.libsdl.org/show_bug.cgi?id=3905

> About the newly added Mix_strtok_safe(): is it truly needed?
> Does Mix_EachSoundFont() need reentrancy??

I added Mix_strtok_safe() to remove ugliness and having to fell into unsafe "strtok()" which I want to avoid. Therefore I made Mix_strtok_safe(). Anyway, to be clear, I have suggested to add it into mainstream SDL as "SDL_strtok()" https://bugzilla.libsdl.org/show_bug.cgi?id=4046 to completely solve this (and other cases in other projects where "strtok()" is used).

> About the new MIX_UNUSED macro: it has multiple definitions in many places. Is there the same place to put it so that every module can see it?

You right, it should be in the united place, probably a new header, or one which is shared between most of the modules. The reason why I made multiple definitions because I didn't want to make new files in far past, which is... mistake, and I should add a small header to declare MIX_UNUSED() macro.
Comment 7 Ozkan Sezer 2019-11-18 08:20:53 UTC
(In reply to Vitaly Novichkov from comment #6)
> [...] having to fell into unsafe "strtok()"

Asking again: Does Mix_EachSoundFont() need reentrancy?
Do we need safety of strtok_r() in there?

> https://bugzilla.libsdl.org/show_bug.cgi?id=4046

Added my note there.

> > About the new MIX_UNUSED macro: it has multiple definitions [...]
> 
> You right, it should be in the united place, probably a new header
> [...]

Or we can replace all instances of MIX_UNUSED(x) with plain
(void)x..  SDL itself doesn't have such a macro, why should
SDL_mixer have it.
Comment 8 Vitaly Novichkov 2019-11-18 08:28:32 UTC
> Or we can replace all instances of MIX_UNUSED(x) with plain
(void)x..  SDL itself doesn't have such a macro, why should
SDL_mixer have it.

I added the macro for convenience and nicer look (Inspired by Q_UNUSED() macro in Qt). Yeah, plain (void)x also should work. Yeah, you would introduce this macro into SDL as `SDL_UNUSED()` or something like, to use it for warning fixes.

> Asking again: Does Mix_EachSoundFont() need reentrancy? Do we need safety of strtok_r() in there?

There are applications that can dynamically change sound fonts on the fly (together with a song switching). Therefore, concurrent using of unsafe `strtok()` will lead to a crash. At the same time, an application may use strtok() by itself, and when it's run in multiple threads, you know the result.
Comment 9 Ozkan Sezer 2019-11-18 08:48:38 UTC
(In reply to Vitaly Novichkov from comment #8)
> introduce this macro into SDL as `SDL_UNUSED()` or something like

SDL does have an SDL_UNUSED macro with a completely different
meaning.  I'm leaning on replacing MIX_UNUSED(x) with (void)x
if no objections.
Comment 10 Vitaly Novichkov 2019-11-18 10:25:03 UTC
Ozkan, one small note:

https://github.com/WohlSoft/SDL-Mixer-X/commit/37377d89743d5c71f13f5a5cfce0e48986797cfa

I removed this beautifying because of bunch of scarying GCC7+ warnings:

```
effect_position.c:1844: предупреждение: this ‘if’ clause does not guard... [-Wmisleading-indentation]
     if (left < 0) left = 0; if (left > 255) left = 255;
     ^~
```