mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-02-28 14:24:57 +00:00
Make sure we don't allocate a TLS ID clobbering an application defined one
Fixes https://github.com/libsdl-org/SDL/issues/14359
(cherry picked from commit d9ca0457b5)
This commit is contained in:
@@ -80,6 +80,15 @@ bool SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback dest
|
||||
* will have the same storage index for this id.
|
||||
*/
|
||||
storage_index = SDL_GetAtomicInt(id) - 1;
|
||||
} else {
|
||||
// Make sure we don't allocate an ID clobbering this one
|
||||
int tls_id = SDL_GetAtomicInt(&SDL_tls_id);
|
||||
while (storage_index >= tls_id) {
|
||||
if (SDL_CompareAndSwapAtomicInt(&SDL_tls_id, tls_id, storage_index + 1)) {
|
||||
break;
|
||||
}
|
||||
tls_id = SDL_GetAtomicInt(&SDL_tls_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the storage for the current thread
|
||||
|
||||
Reference in New Issue
Block a user