Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SDL_revcpy, which isn't _actually_ in SDL2.
- Loading branch information
Showing
2 changed files
with
11 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
4c5e3b2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation is incorrect. The point of
SDL_revcpy
(reverse copy) is to copy from the end to the start rather than from the start to the end asSDL_memcpy
does, which matters in case the buffers are overlapping. Compare:https://github.com/libsdl-org/SDL-1.2/blob/b8aa08c87e3f6e87bf918e1f2e26ebabe5f07122/src/stdlib/SDL_string.c#L320
vs.
https://github.com/libsdl-org/SDL-1.2/blob/b8aa08c87e3f6e87bf918e1f2e26ebabe5f07122/src/stdlib/SDL_string.c#L276
See also the difference between
memcpy
andmemmove
in the standard C library (except thatmemmove
automatically detects the copy direction to use whereasSDL_revcpy
requires you to manually choose betweenSDL_memcpy
andSDL_revcpy
). So you either have to copy the implementation ofSDL_revcpy
here or callSDL_memmove
, notSDL_memcpy
.4c5e3b2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this bug will lead to corruption of the memory area being moved, so it needs urgent fixing.
4c5e3b2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Note that
SDL_memmove
is also subtly different in that it does not always reverse-copy, but auto-detects the safe direction to use. I am not sure whether that can be an issue in practice. But callingSDL_memcpy
always does the wrong thing ifSDL_revcpy
is expected and will definitely break when used instead ofSDL_revcpy
on overlapping buffers.)4c5e3b2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be resolved in dacb4cf , thanks!