Skip to content

Conversation

@cosinekitty
Copy link

The Microsoft C/C++ compiler warned about possibly
writing too much memory in lines like this:

memset(scratch.grbuf[0], 0, 576*2*sizeof(float));

Although the code is correct, it confuses the compiler
into thinking more memory is being zeroed out than
intended. scratch.grbuf[0] holds only half as many
bytes as scratch.grbuf, but the code intends to
zero out the entire array, not just the first half.

Replaced with identical code that eliminates
the warning:

memset(scratch.grbuf, 0, sizeof(scratch.grbuf));

This is also easier to understand and verify as correct.

The Microsoft C/C++ compiler warned about possibly
writing too much memory in lines like this:

    memset(scratch.grbuf[0], 0, 576*2*sizeof(float));

Although the code is correct, it confuses the compiler
into thinking more memory is being zeroed out than
intended. scratch.grbuf[0] holds only half as many
bytes as scratch.grbuf, but the code intends to
zero out the entire array, not just the first half.

Replaced with identical code that eliminates
the warning:

    memset(scratch.grbuf, 0, sizeof(scratch.grbuf));

This is also easier to understand and verify as correct.
The Visual Studio 2019 C/C++ compiler reported
a warning that the following array accesses in
L3_stereo_process could go out of bounds:

    kl = g_pan[2*ipos];
    kr = g_pan[2*ipos + 1];

The compiler apparently believes that the
value of the expression `HDR_TEST_MPEG1(hdr)`
could change its value when evaluated more than once,
even though it is clear from the code that the header
data is constant. The compiler's false theory results
in a perceived risk of reading outside the array
bounds of `g_pan`.

By explicitly evaluating `HDR_TEST_MPEG1(hdr)`
exactly once and holding its value in a local
variable, the warning disappears.
@cosinekitty cosinekitty changed the title Eliminated warning in Visual Studio 2019. Eliminated warnings in Visual Studio 2019. Jun 12, 2022
manxorist added a commit to OpenMPT/openmpt that referenced this pull request Aug 15, 2024
…eleases/tag/openmpt-2024-08-15-v2> commit 30b5aea9b6d000f197798ddd44476b641a4d0ba7 (2024-08-15). This applies the following pull requests: <lieff/minimp3#126>, <lieff/minimp3#96>, <lieff/minimp3#97>.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@21443 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this pull request Aug 15, 2024
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v2> commit 30b5aea9b6d000f197798ddd44476b641a4d0ba7 (2024-08-15). This applies the following pull requests: <lieff/minimp3#126>, <lieff/minimp3#96>, <lieff/minimp3#97>.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@21444 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this pull request Nov 7, 2025
[Ref] minimp3: Silence warning.
........
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v2> commit 30b5aea9b6d000f197798ddd44476b641a4d0ba7 (2024-08-15). This applies the following pull requests: <lieff/minimp3#126>, <lieff/minimp3#96>, <lieff/minimp3#97>.
........
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v3> commit 2811a29e4115199209fe91ae5217c9c5fc611fa6 (2024-08-15). This applies the following pull requests: <lieff/minimp3#125>.
........
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v4> commit 2811a29e4115199209fe91ae5217c9c5fc611fa6 (2024-08-15). This applies the following pull requests: <lieff/minimp3#127>.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.30@24370 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this pull request Nov 7, 2025
[Ref] minimp3: Silence warning.
........
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v2> commit 30b5aea9b6d000f197798ddd44476b641a4d0ba7 (2024-08-15). This applies the following pull requests: <lieff/minimp3#126>, <lieff/minimp3#96>, <lieff/minimp3#97>.
........
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v3> commit 2811a29e4115199209fe91ae5217c9c5fc611fa6 (2024-08-15). This applies the following pull requests: <lieff/minimp3#125>.
........
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v4> commit 2811a29e4115199209fe91ae5217c9c5fc611fa6 (2024-08-15). This applies the following pull requests: <lieff/minimp3#127>.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.29@24373 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this pull request Nov 7, 2025
[Ref] minimp3: Silence warning.
........
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v2> commit 30b5aea9b6d000f197798ddd44476b641a4d0ba7 (2024-08-15). This applies the following pull requests: <lieff/minimp3#126>, <lieff/minimp3#96>, <lieff/minimp3#97>.
........
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v3> commit 2811a29e4115199209fe91ae5217c9c5fc611fa6 (2024-08-15). This applies the following pull requests: <lieff/minimp3#125>.
........
[Var] minimp3: Update to fork <https://github.com/manxorist/minimp3/releases/tag/openmpt-2024-08-15-v4> commit 2811a29e4115199209fe91ae5217c9c5fc611fa6 (2024-08-15). This applies the following pull requests: <lieff/minimp3#127>.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.28@24377 56274372-70c3-4bfc-bfc3-4c3a0b034d27
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.

1 participant