Skip to content
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

SDL_SemWaitTimeout generic implementation is wrong #394

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

SDL_SemWaitTimeout generic implementation is wrong #394

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Labels

Comments

@SDLBugzilla
Copy link
Collaborator

@SDLBugzilla SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 1.2.13
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2008-03-21 13:29:22 +0000, Henrik Kouri wrote:

SDL_SemWaitTimeout in src/thread/generic/SDL_syssem.c line 179 (SVN trunk):

--sem->count;

should be

if (retval == 0) {
--sem->count;
}

Without this, sem->count will underflow on timeout effectively breaking the semaphore. It appears that the implementation has been wrong since the initial revision. Below is a sample C++ app to demonstrate the problem (should output plain zeros when correct):

#include <SDL.h>
#include

int main(int argc, char* argv[])
{
SDL_Init(0);
SDL_sem* sem = SDL_CreateSemaphore(0);
std::cout << SDL_SemValue(sem) << std::endl;

SDL_SemTryWait(sem);
std::cout << SDL_SemValue(sem) << std::endl;

SDL_SemTryWait(sem);
std::cout << SDL_SemValue(sem) << std::endl;

// Breaks here! Integer underflows!
SDL_SemWaitTimeout(sem, 10);
std::cout << SDL_SemValue(sem) << std::endl;

SDL_SemTryWait(sem);
std::cout << SDL_SemValue(sem) << std::endl;

SDL_SemTryWait(sem);
std::cout << SDL_SemValue(sem) << std::endl;

SDL_DestroySemaphore(sem);
sem = NULL;
SDL_Quit();
return 0;
}

On 2009-09-13 16:33:20 +0000, Ryan C. Gordon wrote:

Tagging this bug with "target-1.2.14" so we can try to resolve it for SDL 1.2.14.

Please note that we may choose to resolve it as WONTFIX. This tag is largely so we have a comprehensive wishlist of bugs to examine for 1.2.14 (and so we can close bugs that we'll never fix, rather than have them live forever in Bugzilla).

--ryan.

On 2009-09-21 00:35:21 +0000, Sam Lantinga wrote:

Fixed in subversion, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant