From eacf1199233719b31d7e703ffe6addeca9a00f24 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 2 Sep 2024 12:56:44 -0700 Subject: [PATCH] Renamed SDL_size_add_overflow() and SDL_size_mul_overflow() --- build-scripts/SDL_migration.cocci | 52 ++++++++++++--------- docs/README-migration.md | 2 + include/SDL3/SDL_oldnames.h | 4 ++ include/SDL3/SDL_stdinc.h | 40 +++++++--------- src/SDL_assert.c | 2 +- src/SDL_log.c | 2 +- src/stdlib/SDL_stdlib.c | 6 +-- src/video/SDL_RLEaccel.c | 4 +- src/video/SDL_surface.c | 10 ++-- src/video/SDL_yuv.c | 26 +++++------ test/testautomation_stdlib.c | 78 +++++++++++++++---------------- 11 files changed, 117 insertions(+), 109 deletions(-) diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci index 03abd962f..b60a9c44a 100644 --- a/build-scripts/SDL_migration.cocci +++ b/build-scripts/SDL_migration.cocci @@ -3594,10 +3594,40 @@ typedef SDL_JoystickGUID, SDL_GUID; @@ - SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP + SDL_HINT_MOUSE_EMULATE_WARP_WITH_RELATIVE +@@ +@@ +- SDL_AtomicSetPtr ++ SDL_AtomicSetPointer + (...) +@@ +@@ +- SDL_AtomicGetPtr ++ SDL_AtomicGetPointer + (...) +@@ +@@ +- SDL_DelEventWatch ++ SDL_RemoveEventWatch + (...) +@@ +@@ +- SDL_DelHintCallback ++ SDL_RemoveHintCallback + (...) +@@ +@@ +- SDL_size_mul_overflow ++ SDL_size_mul_check_overflow + (...) +@@ +@@ +- SDL_size_add_overflow ++ SDL_size_add_check_overflow + (...) // This should be the last rule in the file, since it works on SDL3 functions and previous rules may have renamed old functions. @ bool_return_type @ -identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAlternateImage|SDL_AddVulkanRenderSemaphores|SDL_BindAudioStream|SDL_BindAudioStreams|SDL_BlitSurface|SDL_BlitSurface9Grid|SDL_BlitSurfaceScaled|SDL_BlitSurfaceTiled|SDL_BlitSurfaceTiledWithScale|SDL_BlitSurfaceUnchecked|SDL_BlitSurfaceUncheckedScaled|SDL_CaptureMouse|SDL_ClearAudioStream|SDL_ClearClipboardData|SDL_ClearComposition|SDL_ClearError|SDL_ClearProperty|SDL_ClearSurface|SDL_CloseIO|SDL_CloseStorage|SDL_ConvertAudioSamples|SDL_ConvertEventToRenderCoordinates|SDL_ConvertPixels|SDL_ConvertPixelsAndColorspace|SDL_CopyFile|SDL_CopyProperties|SDL_CopyStorageFile|SDL_CreateDirectory|SDL_CreateStorageDirectory|SDL_CreateWindowAndRenderer|SDL_DateTimeToTime|SDL_DestroyWindowSurface|SDL_DetachVirtualJoystick|SDL_DisableScreenSaver|SDL_EnableScreenSaver|SDL_EnumerateDirectory|SDL_EnumerateProperties|SDL_EnumerateStorageDirectory|SDL_FillSurfaceRect|SDL_FillSurfaceRects|SDL_FlashWindow|SDL_FlipSurface|SDL_FlushAudioStream|SDL_FlushRenderer|SDL_GL_DestroyContext|SDL_GL_GetAttribute|SDL_GL_GetSwapInterval|SDL_GL_LoadLibrary|SDL_GL_MakeCurrent|SDL_GL_SetAttribute|SDL_GL_SetSwapInterval|SDL_GL_SwapWindow|SDL_GetAudioDeviceFormat|SDL_GetAudioStreamFormat|SDL_GetCameraFormat|SDL_GetClosestFullscreenDisplayMode|SDL_GetCurrentRenderOutputSize|SDL_GetCurrentTime|SDL_GetDXGIOutputInfo|SDL_GetDateTimeLocalePreferences|SDL_GetDisplayBounds|SDL_GetDisplayUsableBounds|SDL_GetGDKDefaultUser|SDL_GetGDKTaskQueue|SDL_GetGamepadSensorData|SDL_GetGamepadTouchpadFinger|SDL_GetHapticEffectStatus|SDL_GetJoystickBall|SDL_GetMasksForPixelFormat|SDL_GetPathInfo|SDL_GetRectUnion|SDL_GetRectUnionFloat|SDL_GetRenderClipRect|SDL_GetRenderColorScale|SDL_GetRenderDrawBlendMode|SDL_GetRenderDrawColor|SDL_GetRenderDrawColorFloat|SDL_GetRenderLogicalPresentation|SDL_GetRenderLogicalPresentationRect|SDL_GetRenderOutputSize|SDL_GetRenderSafeArea|SDL_GetRenderScale|SDL_GetRenderVSync|SDL_GetRenderViewport|SDL_GetSensorData|SDL_GetStorageFileSize|SDL_GetStoragePathInfo|SDL_GetSurfaceAlphaMod|SDL_GetSurfaceBlendMode|SDL_GetSurfaceClipRect|SDL_GetSurfaceColorKey|SDL_GetSurfaceColorMod|SDL_GetTextInputArea|SDL_GetTextureAlphaMod|SDL_GetTextureAlphaModFloat|SDL_GetTextureBlendMode|SDL_GetTextureColorMod|SDL_GetTextureColorModFloat|SDL_GetTextureScaleMode|SDL_GetTextureSize|SDL_GetWindowAspectRatio|SDL_GetWindowBordersSize|SDL_GetWindowMaximumSize|SDL_GetWindowMinimumSize|SDL_GetWindowPosition|SDL_GetWindowRelativeMouseMode|SDL_GetWindowSafeArea|SDL_GetWindowSize|SDL_GetWindowSizeInPixels|SDL_GetWindowSurfaceVSync|SDL_HideCursor|SDL_HideWindow|SDL_Init|SDL_InitHapticRumble|SDL_InitSubSystem|SDL_LoadWAV|SDL_LoadWAV_IO|SDL_LockAudioStream|SDL_LockProperties|SDL_LockSurface|SDL_LockTexture|SDL_LockTextureToSurface|SDL_MaximizeWindow|SDL_MinimizeWindow|SDL_MixAudio|SDL_OpenURL|SDL_OutOfMemory|SDL_PauseAudioDevice|SDL_PauseAudioStreamDevice|SDL_PauseHaptic|SDL_PlayHapticRumble|SDL_PremultiplyAlpha|SDL_PremultiplySurfaceAlpha|SDL_PushEvent|SDL_PutAudioStreamData|SDL_RaiseWindow|SDL_ReadStorageFile|SDL_ReadSurfacePixel|SDL_ReadSurfacePixelFloat|SDL_RegisterApp|SDL_ReloadGamepadMappings|SDL_RemovePath|SDL_RemoveStoragePath|SDL_RemoveTimer|SDL_RenamePath|SDL_RenameStoragePath|SDL_RenderClear|SDL_RenderCoordinatesFromWindow|SDL_RenderCoordinatesToWindow|SDL_RenderFillRect|SDL_RenderFillRects|SDL_RenderGeometry|SDL_RenderGeometryRaw|SDL_RenderLine|SDL_RenderLines|SDL_RenderPoint|SDL_RenderPoints|SDL_RenderPresent|SDL_RenderRect|SDL_RenderRects|SDL_RenderTexture|SDL_RenderTexture9Grid|SDL_RenderTextureRotated|SDL_RenderTextureTiled|SDL_RequestAndroidPermission|SDL_RestoreWindow|SDL_ResumeAudioDevice|SDL_ResumeAudioStreamDevice|SDL_ResumeHaptic|SDL_RumbleGamepad|SDL_RumbleGamepadTriggers|SDL_RumbleJoystick|SDL_RumbleJoystickTriggers|SDL_RunHapticEffect|SDL_SaveBMP|SDL_SaveBMP_IO|SDL_SendAndroidMessage|SDL_SendGamepadEffect|SDL_SendJoystickEffect|SDL_SendJoystickVirtualSensorData|SDL_SetAppMetadata|SDL_SetAppMetadataProperty|SDL_SetAudioDeviceGain|SDL_SetAudioPostmixCallback|SDL_SetAudioStreamFormat|SDL_SetAudioStreamFrequencyRatio|SDL_SetAudioStreamGain|SDL_SetAudioStreamGetCallback|SDL_SetAudioStreamInputChannelMap|SDL_SetAudioStreamOutputChannelMap|SDL_SetAudioStreamPutCallback|SDL_SetBooleanProperty|SDL_SetClipboardData|SDL_SetClipboardText|SDL_SetCursor|SDL_SetFloatProperty|SDL_SetGamepadLED|SDL_SetGamepadMapping|SDL_SetGamepadPlayerIndex|SDL_SetGamepadSensorEnabled|SDL_SetHapticAutocenter|SDL_SetHapticGain|SDL_SetJoystickLED|SDL_SetJoystickPlayerIndex|SDL_SetJoystickVirtualAxis|SDL_SetJoystickVirtualBall|SDL_SetJoystickVirtualButton|SDL_SetJoystickVirtualHat|SDL_SetJoystickVirtualTouchpad|SDL_SetLinuxThreadPriority|SDL_SetLinuxThreadPriorityAndPolicy|SDL_SetLogPriorityPrefix|SDL_SetMemoryFunctions|SDL_SetNumberProperty|SDL_SetPaletteColors|SDL_SetPointerProperty|SDL_SetPointerPropertyWithCleanup|SDL_SetPrimarySelectionText|SDL_SetRenderClipRect|SDL_SetRenderColorScale|SDL_SetRenderDrawBlendMode|SDL_SetRenderDrawColor|SDL_SetRenderDrawColorFloat|SDL_SetRenderLogicalPresentation|SDL_SetRenderScale|SDL_SetRenderTarget|SDL_SetRenderVSync|SDL_SetRenderViewport|SDL_SetScancodeName|SDL_SetStringProperty|SDL_SetSurfaceAlphaMod|SDL_SetSurfaceBlendMode|SDL_SetSurfaceColorKey|SDL_SetSurfaceColorMod|SDL_SetSurfaceColorspace|SDL_SetSurfacePalette|SDL_SetSurfaceRLE|SDL_SetTLS|SDL_SetTextInputArea|SDL_SetTextureAlphaMod|SDL_SetTextureAlphaModFloat|SDL_SetTextureBlendMode|SDL_SetTextureColorMod|SDL_SetTextureColorModFloat|SDL_SetTextureScaleMode|SDL_SetThreadPriority|SDL_SetWindowAlwaysOnTop|SDL_SetWindowAspectRatio|SDL_SetWindowBordered|SDL_SetWindowFocusable|SDL_SetWindowFullscreen|SDL_SetWindowFullscreenMode|SDL_SetWindowHitTest|SDL_SetWindowIcon|SDL_SetWindowKeyboardGrab|SDL_SetWindowMaximumSize|SDL_SetWindowMinimumSize|SDL_SetWindowModalFor|SDL_SetWindowMouseGrab|SDL_SetWindowMouseRect|SDL_SetWindowOpacity|SDL_SetWindowPosition|SDL_SetWindowRelativeMouseMode|SDL_SetWindowResizable|SDL_SetWindowShape|SDL_SetWindowSize|SDL_SetWindowSurfaceVSync|SDL_SetWindowTitle|SDL_SetiOSAnimationCallback|SDL_ShowAndroidToast|SDL_ShowCursor|SDL_ShowMessageBox|SDL_ShowSimpleMessageBox|SDL_ShowWindow|SDL_ShowWindowSystemMenu|SDL_StartTextInput|SDL_StartTextInputWithProperties|SDL_StopHapticEffect|SDL_StopHapticEffects|SDL_StopHapticRumble|SDL_StopTextInput|SDL_SyncWindow|SDL_TimeToDateTime|SDL_TryLockMutex|SDL_TryLockRWLockForReading|SDL_TryLockRWLockForWriting|SDL_TryWaitSemaphore|SDL_UnlockAudioStream|SDL_UpdateHapticEffect|SDL_UpdateNVTexture|SDL_UpdateTexture|SDL_UpdateWindowSurface|SDL_UpdateWindowSurfaceRects|SDL_UpdateYUVTexture|SDL_Vulkan_CreateSurface|SDL_Vulkan_LoadLibrary|SDL_WaitConditionTimeout|SDL_WaitSemaphoreTimeout|SDL_WarpMouseGlobal|SDL_WriteStorageFile|SDL_WriteSurfacePixel|SDL_WriteSurfacePixelFloat)$"; +identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAlternateImage|SDL_AddVulkanRenderSemaphores|SDL_BindAudioStream|SDL_BindAudioStreams|SDL_BlitSurface|SDL_BlitSurface9Grid|SDL_BlitSurfaceScaled|SDL_BlitSurfaceTiled|SDL_BlitSurfaceTiledWithScale|SDL_BlitSurfaceUnchecked|SDL_BlitSurfaceUncheckedScaled|SDL_CaptureMouse|SDL_ClearAudioStream|SDL_ClearClipboardData|SDL_ClearComposition|SDL_ClearError|SDL_ClearProperty|SDL_ClearSurface|SDL_CloseIO|SDL_CloseStorage|SDL_ConvertAudioSamples|SDL_ConvertEventToRenderCoordinates|SDL_ConvertPixels|SDL_ConvertPixelsAndColorspace|SDL_CopyFile|SDL_CopyProperties|SDL_CopyStorageFile|SDL_CreateDirectory|SDL_CreateStorageDirectory|SDL_CreateWindowAndRenderer|SDL_DateTimeToTime|SDL_DestroyWindowSurface|SDL_DetachVirtualJoystick|SDL_DisableScreenSaver|SDL_EnableScreenSaver|SDL_EnumerateDirectory|SDL_EnumerateProperties|SDL_EnumerateStorageDirectory|SDL_FillSurfaceRect|SDL_FillSurfaceRects|SDL_FlashWindow|SDL_FlipSurface|SDL_FlushAudioStream|SDL_FlushRenderer|SDL_GL_DestroyContext|SDL_GL_GetAttribute|SDL_GL_GetSwapInterval|SDL_GL_LoadLibrary|SDL_GL_MakeCurrent|SDL_GL_SetAttribute|SDL_GL_SetSwapInterval|SDL_GL_SwapWindow|SDL_GetAudioDeviceFormat|SDL_GetAudioStreamFormat|SDL_GetCameraFormat|SDL_GetClosestFullscreenDisplayMode|SDL_GetCurrentRenderOutputSize|SDL_GetCurrentTime|SDL_GetDXGIOutputInfo|SDL_GetDateTimeLocalePreferences|SDL_GetDisplayBounds|SDL_GetDisplayUsableBounds|SDL_GetGDKDefaultUser|SDL_GetGDKTaskQueue|SDL_GetGamepadSensorData|SDL_GetGamepadTouchpadFinger|SDL_GetHapticEffectStatus|SDL_GetJoystickBall|SDL_GetMasksForPixelFormat|SDL_GetPathInfo|SDL_GetRectUnion|SDL_GetRectUnionFloat|SDL_GetRenderClipRect|SDL_GetRenderColorScale|SDL_GetRenderDrawBlendMode|SDL_GetRenderDrawColor|SDL_GetRenderDrawColorFloat|SDL_GetRenderLogicalPresentation|SDL_GetRenderLogicalPresentationRect|SDL_GetRenderOutputSize|SDL_GetRenderSafeArea|SDL_GetRenderScale|SDL_GetRenderVSync|SDL_GetRenderViewport|SDL_GetSensorData|SDL_GetStorageFileSize|SDL_GetStoragePathInfo|SDL_GetSurfaceAlphaMod|SDL_GetSurfaceBlendMode|SDL_GetSurfaceClipRect|SDL_GetSurfaceColorKey|SDL_GetSurfaceColorMod|SDL_GetTextInputArea|SDL_GetTextureAlphaMod|SDL_GetTextureAlphaModFloat|SDL_GetTextureBlendMode|SDL_GetTextureColorMod|SDL_GetTextureColorModFloat|SDL_GetTextureScaleMode|SDL_GetTextureSize|SDL_GetWindowAspectRatio|SDL_GetWindowBordersSize|SDL_GetWindowMaximumSize|SDL_GetWindowMinimumSize|SDL_GetWindowPosition|SDL_GetWindowRelativeMouseMode|SDL_GetWindowSafeArea|SDL_GetWindowSize|SDL_GetWindowSizeInPixels|SDL_GetWindowSurfaceVSync|SDL_HideCursor|SDL_HideWindow|SDL_Init|SDL_InitHapticRumble|SDL_InitSubSystem|SDL_LoadWAV|SDL_LoadWAV_IO|SDL_LockAudioStream|SDL_LockProperties|SDL_LockSurface|SDL_LockTexture|SDL_LockTextureToSurface|SDL_MaximizeWindow|SDL_MinimizeWindow|SDL_MixAudio|SDL_OpenURL|SDL_OutOfMemory|SDL_PauseAudioDevice|SDL_PauseAudioStreamDevice|SDL_PauseHaptic|SDL_PlayHapticRumble|SDL_PremultiplyAlpha|SDL_PremultiplySurfaceAlpha|SDL_PushEvent|SDL_PutAudioStreamData|SDL_RaiseWindow|SDL_ReadStorageFile|SDL_ReadSurfacePixel|SDL_ReadSurfacePixelFloat|SDL_RegisterApp|SDL_ReloadGamepadMappings|SDL_RemovePath|SDL_RemoveStoragePath|SDL_RemoveTimer|SDL_RenamePath|SDL_RenameStoragePath|SDL_RenderClear|SDL_RenderCoordinatesFromWindow|SDL_RenderCoordinatesToWindow|SDL_RenderFillRect|SDL_RenderFillRects|SDL_RenderGeometry|SDL_RenderGeometryRaw|SDL_RenderLine|SDL_RenderLines|SDL_RenderPoint|SDL_RenderPoints|SDL_RenderPresent|SDL_RenderRect|SDL_RenderRects|SDL_RenderTexture|SDL_RenderTexture9Grid|SDL_RenderTextureRotated|SDL_RenderTextureTiled|SDL_RequestAndroidPermission|SDL_RestoreWindow|SDL_ResumeAudioDevice|SDL_ResumeAudioStreamDevice|SDL_ResumeHaptic|SDL_RumbleGamepad|SDL_RumbleGamepadTriggers|SDL_RumbleJoystick|SDL_RumbleJoystickTriggers|SDL_RunHapticEffect|SDL_SaveBMP|SDL_SaveBMP_IO|SDL_SendAndroidMessage|SDL_SendGamepadEffect|SDL_SendJoystickEffect|SDL_SendJoystickVirtualSensorData|SDL_SetAppMetadata|SDL_SetAppMetadataProperty|SDL_SetAudioDeviceGain|SDL_SetAudioPostmixCallback|SDL_SetAudioStreamFormat|SDL_SetAudioStreamFrequencyRatio|SDL_SetAudioStreamGain|SDL_SetAudioStreamGetCallback|SDL_SetAudioStreamInputChannelMap|SDL_SetAudioStreamOutputChannelMap|SDL_SetAudioStreamPutCallback|SDL_SetBooleanProperty|SDL_SetClipboardData|SDL_SetClipboardText|SDL_SetCursor|SDL_SetFloatProperty|SDL_SetGamepadLED|SDL_SetGamepadMapping|SDL_SetGamepadPlayerIndex|SDL_SetGamepadSensorEnabled|SDL_SetHapticAutocenter|SDL_SetHapticGain|SDL_SetJoystickLED|SDL_SetJoystickPlayerIndex|SDL_SetJoystickVirtualAxis|SDL_SetJoystickVirtualBall|SDL_SetJoystickVirtualButton|SDL_SetJoystickVirtualHat|SDL_SetJoystickVirtualTouchpad|SDL_SetLinuxThreadPriority|SDL_SetLinuxThreadPriorityAndPolicy|SDL_SetLogPriorityPrefix|SDL_SetMemoryFunctions|SDL_SetNumberProperty|SDL_SetPaletteColors|SDL_SetPointerProperty|SDL_SetPointerPropertyWithCleanup|SDL_SetPrimarySelectionText|SDL_SetRenderClipRect|SDL_SetRenderColorScale|SDL_SetRenderDrawBlendMode|SDL_SetRenderDrawColor|SDL_SetRenderDrawColorFloat|SDL_SetRenderLogicalPresentation|SDL_SetRenderScale|SDL_SetRenderTarget|SDL_SetRenderVSync|SDL_SetRenderViewport|SDL_SetScancodeName|SDL_SetStringProperty|SDL_SetSurfaceAlphaMod|SDL_SetSurfaceBlendMode|SDL_SetSurfaceColorKey|SDL_SetSurfaceColorMod|SDL_SetSurfaceColorspace|SDL_SetSurfacePalette|SDL_SetSurfaceRLE|SDL_SetTLS|SDL_SetTextInputArea|SDL_SetTextureAlphaMod|SDL_SetTextureAlphaModFloat|SDL_SetTextureBlendMode|SDL_SetTextureColorMod|SDL_SetTextureColorModFloat|SDL_SetTextureScaleMode|SDL_SetThreadPriority|SDL_SetWindowAlwaysOnTop|SDL_SetWindowAspectRatio|SDL_SetWindowBordered|SDL_SetWindowFocusable|SDL_SetWindowFullscreen|SDL_SetWindowFullscreenMode|SDL_SetWindowHitTest|SDL_SetWindowIcon|SDL_SetWindowKeyboardGrab|SDL_SetWindowMaximumSize|SDL_SetWindowMinimumSize|SDL_SetWindowModalFor|SDL_SetWindowMouseGrab|SDL_SetWindowMouseRect|SDL_SetWindowOpacity|SDL_SetWindowPosition|SDL_SetWindowRelativeMouseMode|SDL_SetWindowResizable|SDL_SetWindowShape|SDL_SetWindowSize|SDL_SetWindowSurfaceVSync|SDL_SetWindowTitle|SDL_SetiOSAnimationCallback|SDL_ShowAndroidToast|SDL_ShowCursor|SDL_ShowMessageBox|SDL_ShowSimpleMessageBox|SDL_ShowWindow|SDL_ShowWindowSystemMenu|SDL_StartTextInput|SDL_StartTextInputWithProperties|SDL_StopHapticEffect|SDL_StopHapticEffects|SDL_StopHapticRumble|SDL_StopTextInput|SDL_SyncWindow|SDL_TimeToDateTime|SDL_TryLockMutex|SDL_TryLockRWLockForReading|SDL_TryLockRWLockForWriting|SDL_TryWaitSemaphore|SDL_UnlockAudioStream|SDL_UpdateHapticEffect|SDL_UpdateNVTexture|SDL_UpdateTexture|SDL_UpdateWindowSurface|SDL_UpdateWindowSurfaceRects|SDL_UpdateYUVTexture|SDL_Vulkan_CreateSurface|SDL_Vulkan_LoadLibrary|SDL_WaitConditionTimeout|SDL_WaitSemaphoreTimeout|SDL_WarpMouseGlobal|SDL_WriteStorageFile|SDL_WriteSurfacePixel|SDL_WriteSurfacePixelFloat|SDL_size_mul_check_overflow|SDL_size_add_check_overflow)$"; @@ ( func( @@ -3623,23 +3653,3 @@ identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAltern ) - == -1 ) -@@ -@@ -- SDL_AtomicSetPtr -+ SDL_AtomicSetPointer - (...) -@@ -@@ -- SDL_AtomicGetPtr -+ SDL_AtomicGetPointer - (...) -@@ -@@ -- SDL_DelEventWatch -+ SDL_RemoveEventWatch - (...) -@@ -@@ -- SDL_DelHintCallback -+ SDL_RemoveHintCallback - (...) diff --git a/docs/README-migration.md b/docs/README-migration.md index 43c88141f..303ea2d5b 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -1723,6 +1723,8 @@ The following macros have been removed: * SDL_TABLESIZE() - use SDL_arraysize() instead The following functions have been renamed: +* SDL_size_add_overflow() => SDL_size_add_check_overflow() +* SDL_size_mul_overflow() => SDL_size_mul_check_overflow() * SDL_strtokr() => SDL_strtok_r() The following functions have been removed: diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h index 02c881c68..2795191ce 100644 --- a/include/SDL3/SDL_oldnames.h +++ b/include/SDL3/SDL_oldnames.h @@ -581,6 +581,8 @@ /* ##SDL_stdinc.h */ #define SDL_TABLESIZE SDL_arraysize +#define SDL_size_add_overflow SDL_size_add_check_overflow +#define SDL_size_mul_overflow SDL_size_mul_check_overflow #define SDL_strtokr SDL_strtok_r /* ##SDL_surface.h */ @@ -1205,6 +1207,8 @@ /* ##SDL_stdinc.h */ #define SDL_TABLESIZE SDL_TABLESIZE_renamed_SDL_arraysize +#define SDL_size_add_overflow SDL_size_add_overflow_renamed_SDL_size_add_check_overflow +#define SDL_size_mul_overflow SDL_size_mul_overflow_renamed_SDL_size_mul_check_overflow #define SDL_strtokr SDL_strtokr_renamed_SDL_strtok_r /* ##SDL_surface.h */ diff --git a/include/SDL3/SDL_stdinc.h b/include/SDL3/SDL_stdinc.h index 5539f2a81..ddb0cc750 100644 --- a/include/SDL3/SDL_stdinc.h +++ b/include/SDL3/SDL_stdinc.h @@ -3082,29 +3082,27 @@ size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size); /** * Multiply two integers, checking for overflow. * - * If `a * b` would overflow, return -1. + * If `a * b` would overflow, return SDL_FALSE. * - * Otherwise store `a * b` via ret and return 0. + * Otherwise store `a * b` via ret and return SDL_TRUE. * * \param a the multiplicand. * \param b the multiplier. * \param ret on non-overflow output, stores the multiplication result. May * not be NULL. - * \returns -1 on overflow, 0 if result doesn't overflow. + * \returns SDL_FALSE on overflow, SDL_TRUE if result is multiplied without overflow. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -SDL_FORCE_INLINE int SDL_size_mul_overflow (size_t a, - size_t b, - size_t *ret) +SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow(size_t a, size_t b, size_t *ret) { if (a != 0 && b > SDL_SIZE_MAX / a) { - return -1; + return SDL_FALSE; } *ret = a * b; - return 0; + return SDL_TRUE; } #ifndef SDL_WIKI_DOCUMENTATION_SECTION @@ -3112,13 +3110,11 @@ SDL_FORCE_INLINE int SDL_size_mul_overflow (size_t a, /* This needs to be wrapped in an inline rather than being a direct #define, * because __builtin_mul_overflow() is type-generic, but we want to be * consistent about interpreting a and b as size_t. */ -SDL_FORCE_INLINE int SDL_size_mul_overflow_builtin (size_t a, - size_t b, - size_t *ret) +SDL_FORCE_INLINE SDL_bool SDL_size_mul_check_overflow_builtin(size_t a, size_t b, size_t *ret) { - return __builtin_mul_overflow(a, b, ret) == 0 ? 0 : -1; + return (__builtin_mul_overflow(a, b, ret) == 0); } -#define SDL_size_mul_overflow(a, b, ret) (SDL_size_mul_overflow_builtin(a, b, ret)) +#define SDL_size_mul_check_overflow(a, b, ret) SDL_size_mul_check_overflow_builtin(a, b, ret) #endif #endif @@ -3133,34 +3129,30 @@ SDL_FORCE_INLINE int SDL_size_mul_overflow_builtin (size_t a, * \param b the second addend. * \param ret on non-overflow output, stores the addition result. May not be * NULL. - * \returns -1 on overflow, 0 if result doesn't overflow. + * \returns SDL_FALSE on overflow, SDL_TRUE if result is added without overflow. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -SDL_FORCE_INLINE int SDL_size_add_overflow (size_t a, - size_t b, - size_t *ret) +SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow(size_t a, size_t b, size_t *ret) { if (b > SDL_SIZE_MAX - a) { - return -1; + return SDL_FALSE; } *ret = a + b; - return 0; + return SDL_TRUE; } #ifndef SDL_WIKI_DOCUMENTATION_SECTION #if SDL_HAS_BUILTIN(__builtin_add_overflow) /* This needs to be wrapped in an inline rather than being a direct #define, * the same as the call to __builtin_mul_overflow() above. */ -SDL_FORCE_INLINE int SDL_size_add_overflow_builtin (size_t a, - size_t b, - size_t *ret) +SDL_FORCE_INLINE SDL_bool SDL_size_add_check_overflow_builtin(size_t a, size_t b, size_t *ret) { - return __builtin_add_overflow(a, b, ret) == 0 ? 0 : -1; + return (__builtin_add_overflow(a, b, ret) == 0); } -#define SDL_size_add_overflow(a, b, ret) (SDL_size_add_overflow_builtin(a, b, ret)) +#define SDL_size_add_check_overflow(a, b, ret) SDL_size_add_check_overflow_builtin(a, b, ret) #endif #endif diff --git a/src/SDL_assert.c b/src/SDL_assert.c index 95d212237..986f08ee0 100644 --- a/src/SDL_assert.c +++ b/src/SDL_assert.c @@ -175,7 +175,7 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v // .. and if it didn't, try to allocate as much room as we actually need. if (len >= (int)buf_len) { - if (SDL_size_add_overflow(len, 1, &buf_len) == 0) { + if (SDL_size_add_check_overflow(len, 1, &buf_len)) { message = (char *)SDL_malloc(buf_len); if (message) { len = SDL_RenderAssertMessage(message, buf_len, data); diff --git a/src/SDL_log.c b/src/SDL_log.c index e9c48b596..f09289a29 100644 --- a/src/SDL_log.c +++ b/src/SDL_log.c @@ -480,7 +480,7 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_S } // If message truncated, allocate and re-render - if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) { + if (len >= sizeof(stack_buf) && SDL_size_add_check_overflow(len, 1, &len_plus_term)) { // Allocate exactly what we need, including the zero-terminator message = (char *)SDL_malloc(len_plus_term); if (!message) { diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index 45e6ba9be..2d08ed719 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -539,9 +539,9 @@ void *SDL_aligned_alloc(size_t alignment, size_t size) } padding = (alignment - (size % alignment)); - if (SDL_size_add_overflow(size, alignment, &size) == 0 && - SDL_size_add_overflow(size, sizeof(void *), &size) == 0 && - SDL_size_add_overflow(size, padding, &size) == 0) { + if (SDL_size_add_check_overflow(size, alignment, &size) && + SDL_size_add_check_overflow(size, sizeof(void *), &size) && + SDL_size_add_check_overflow(size, padding, &size)) { void *original = SDL_malloc(size); if (original) { // Make sure we have enough space to store the original pointer diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index 904ca30d9..9712908b6 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -1456,7 +1456,7 @@ static bool UnRLEAlpha(SDL_Surface *surface) uncopy_opaque = uncopy_transl = uncopy_32; } - if (SDL_size_mul_overflow(surface->h, surface->pitch, &size)) { + if (!SDL_size_mul_check_overflow(surface->h, surface->pitch, &size)) { return false; } @@ -1527,7 +1527,7 @@ void SDL_UnRLESurface(SDL_Surface *surface, bool recode) size_t size; // re-create the original surface - if (SDL_size_mul_overflow(surface->h, surface->pitch, &size)) { + if (!SDL_size_mul_check_overflow(surface->h, surface->pitch, &size)) { // Memory corruption? surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; return; diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 1522616b4..27812af70 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -61,27 +61,27 @@ void SDL_UpdateSurfaceLockFlag(SDL_Surface *surface) static bool SDL_CalculateRGBSize(Uint32 format, size_t width, size_t height, size_t *size, size_t *pitch, bool minimal) { if (SDL_BITSPERPIXEL(format) >= 8) { - if (SDL_size_mul_overflow(width, SDL_BYTESPERPIXEL(format), pitch)) { + if (!SDL_size_mul_check_overflow(width, SDL_BYTESPERPIXEL(format), pitch)) { return SDL_SetError("width * bpp would overflow"); } } else { - if (SDL_size_mul_overflow(width, SDL_BITSPERPIXEL(format), pitch)) { + if (!SDL_size_mul_check_overflow(width, SDL_BITSPERPIXEL(format), pitch)) { return SDL_SetError("width * bpp would overflow"); } - if (SDL_size_add_overflow(*pitch, 7, pitch)) { + if (!SDL_size_add_check_overflow(*pitch, 7, pitch)) { return SDL_SetError("aligning pitch would overflow"); } *pitch /= 8; } if (!minimal) { // 4-byte aligning for speed - if (SDL_size_add_overflow(*pitch, 3, pitch)) { + if (!SDL_size_add_check_overflow(*pitch, 3, pitch)) { return SDL_SetError("aligning pitch would overflow"); } *pitch &= ~3; } - if (SDL_size_mul_overflow(height, *pitch, size)) { + if (!SDL_size_mul_check_overflow(height, *pitch, size)) { return SDL_SetError("height * pitch would overflow"); } diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c index d7ddd0790..81ace699a 100644 --- a/src/video/SDL_yuv.c +++ b/src/video/SDL_yuv.c @@ -43,7 +43,7 @@ bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, si { /* sz_plane == w * h; */ size_t s1; - if (SDL_size_mul_overflow(w, h, &s1) < 0) { + if (!SDL_size_mul_check_overflow(w, h, &s1)) { return SDL_SetError("width * height would overflow"); } sz_plane = (int) s1; @@ -52,15 +52,15 @@ bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, si { /* sz_plane_chroma == ((w + 1) / 2) * ((h + 1) / 2); */ size_t s1, s2, s3; - if (SDL_size_add_overflow(w, 1, &s1) < 0) { + if (!SDL_size_add_check_overflow(w, 1, &s1)) { return SDL_SetError("width + 1 would overflow"); } s1 = s1 / 2; - if (SDL_size_add_overflow(h, 1, &s2) < 0) { + if (!SDL_size_add_check_overflow(h, 1, &s2)) { return SDL_SetError("height + 1 would overflow"); } s2 = s2 / 2; - if (SDL_size_mul_overflow(s1, s2, &s3) < 0) { + if (!SDL_size_mul_check_overflow(s1, s2, &s3)) { return SDL_SetError("width * height would overflow"); } sz_plane_chroma = (int) s3; @@ -68,11 +68,11 @@ bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, si } else { /* sz_plane_packed == ((w + 1) / 2) * h; */ size_t s1, s2; - if (SDL_size_add_overflow(w, 1, &s1) < 0) { + if (!SDL_size_add_check_overflow(w, 1, &s1)) { return SDL_SetError("width + 1 would overflow"); } s1 = s1 / 2; - if (SDL_size_mul_overflow(s1, h, &s2) < 0) { + if (!SDL_size_mul_check_overflow(s1, h, &s2)) { return SDL_SetError("width * height would overflow"); } sz_plane_packed = (int) s2; @@ -89,10 +89,10 @@ bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, si if (size) { // dst_size == sz_plane + sz_plane_chroma + sz_plane_chroma; size_t s1, s2; - if (SDL_size_add_overflow(sz_plane, sz_plane_chroma, &s1) < 0) { + if (!SDL_size_add_check_overflow(sz_plane, sz_plane_chroma, &s1)) { return SDL_SetError("Y + U would overflow"); } - if (SDL_size_add_overflow(s1, sz_plane_chroma, &s2) < 0) { + if (!SDL_size_add_check_overflow(s1, sz_plane_chroma, &s2)) { return SDL_SetError("Y + U + V would overflow"); } *size = (int)s2; @@ -106,11 +106,11 @@ bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, si if (pitch) { /* pitch == ((w + 1) / 2) * 4; */ size_t p1, p2; - if (SDL_size_add_overflow(w, 1, &p1) < 0) { + if (!SDL_size_add_check_overflow(w, 1, &p1)) { return SDL_SetError("width + 1 would overflow"); } p1 = p1 / 2; - if (SDL_size_mul_overflow(p1, 4, &p2) < 0) { + if (!SDL_size_mul_check_overflow(p1, 4, &p2)) { return SDL_SetError("width * 4 would overflow"); } *pitch = p2; @@ -119,7 +119,7 @@ bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, si if (size) { /* dst_size == 4 * sz_plane_packed; */ size_t s1; - if (SDL_size_mul_overflow(sz_plane_packed, 4, &s1) < 0) { + if (!SDL_size_mul_check_overflow(sz_plane_packed, 4, &s1)) { return SDL_SetError("plane * 4 would overflow"); } *size = (int) s1; @@ -135,10 +135,10 @@ bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, si if (size) { // dst_size == sz_plane + sz_plane_chroma + sz_plane_chroma; size_t s1, s2; - if (SDL_size_add_overflow(sz_plane, sz_plane_chroma, &s1) < 0) { + if (!SDL_size_add_check_overflow(sz_plane, sz_plane_chroma, &s1)) { return SDL_SetError("Y + U would overflow"); } - if (SDL_size_add_overflow(s1, sz_plane_chroma, &s2) < 0) { + if (!SDL_size_add_check_overflow(s1, sz_plane_chroma, &s2)) { return SDL_SetError("Y + U + V would overflow"); } *size = (int) s2; diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c index 5e649ab39..be87103ec 100644 --- a/test/testautomation_stdlib.c +++ b/test/testautomation_stdlib.c @@ -917,32 +917,32 @@ typedef struct size_t a; size_t b; size_t result; - int status; + SDL_bool status; } overflow_test; static const overflow_test multiplications[] = { - { 1, 1, 1, 0 }, - { 0, 0, 0, 0 }, - { SDL_SIZE_MAX, 0, 0, 0 }, - { SDL_SIZE_MAX, 1, SDL_SIZE_MAX, 0 }, - { SDL_SIZE_MAX / 2, 2, SDL_SIZE_MAX - (SDL_SIZE_MAX % 2), 0 }, - { SDL_SIZE_MAX / 23, 23, SDL_SIZE_MAX - (SDL_SIZE_MAX % 23), 0 }, + { 1, 1, 1, SDL_TRUE }, + { 0, 0, 0, SDL_TRUE }, + { SDL_SIZE_MAX, 0, 0, SDL_TRUE }, + { SDL_SIZE_MAX, 1, SDL_SIZE_MAX, SDL_TRUE }, + { SDL_SIZE_MAX / 2, 2, SDL_SIZE_MAX - (SDL_SIZE_MAX % 2), SDL_TRUE }, + { SDL_SIZE_MAX / 23, 23, SDL_SIZE_MAX - (SDL_SIZE_MAX % 23), SDL_TRUE }, - { (SDL_SIZE_MAX / 2) + 1, 2, 0, -1 }, - { (SDL_SIZE_MAX / 23) + 42, 23, 0, -1 }, - { SDL_SIZE_MAX, SDL_SIZE_MAX, 0, -1 }, + { (SDL_SIZE_MAX / 2) + 1, 2, 0, SDL_FALSE }, + { (SDL_SIZE_MAX / 23) + 42, 23, 0, SDL_FALSE }, + { SDL_SIZE_MAX, SDL_SIZE_MAX, 0, SDL_FALSE }, }; static const overflow_test additions[] = { - { 1, 1, 2, 0 }, - { 0, 0, 0, 0 }, - { SDL_SIZE_MAX, 0, SDL_SIZE_MAX, 0 }, - { SDL_SIZE_MAX - 1, 1, SDL_SIZE_MAX, 0 }, - { SDL_SIZE_MAX - 42, 23, SDL_SIZE_MAX - (42 - 23), 0 }, + { 1, 1, 2, SDL_TRUE }, + { 0, 0, 0, SDL_TRUE }, + { SDL_SIZE_MAX, 0, SDL_SIZE_MAX, SDL_TRUE }, + { SDL_SIZE_MAX - 1, 1, SDL_SIZE_MAX, SDL_TRUE }, + { SDL_SIZE_MAX - 42, 23, SDL_SIZE_MAX - (42 - 23), SDL_TRUE }, - { SDL_SIZE_MAX, 1, 0, -1 }, - { SDL_SIZE_MAX, 23, 0, -1 }, - { SDL_SIZE_MAX, SDL_SIZE_MAX, 0, -1 }, + { SDL_SIZE_MAX, 1, 0, SDL_FALSE }, + { SDL_SIZE_MAX, 23, 0, SDL_FALSE }, + { SDL_SIZE_MAX, SDL_SIZE_MAX, 0, SDL_FALSE }, }; static int @@ -964,22 +964,22 @@ stdlib_overflow(void *arg) size_t result = ~t->result; if (useBuiltin) { - status = SDL_size_mul_overflow(t->a, t->b, &result); + status = SDL_size_mul_check_overflow(t->a, t->b, &result); } else { /* This disables the macro that tries to use a gcc/clang * builtin, so we test the fallback implementation instead. */ - status = (SDL_size_mul_overflow)(t->a, t->b, &result); + status = (SDL_size_mul_check_overflow)(t->a, t->b, &result); } - if (t->status == 0) { - SDLTest_AssertCheck(status == 0, + if (t->status) { + SDLTest_AssertCheck(status, "(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed", t->a, t->b); SDLTest_AssertCheck(result == t->result, "(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT, t->a, t->b, t->result, result); } else { - SDLTest_AssertCheck(status == -1, + SDLTest_AssertCheck(!status, "(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail", t->a, t->b); } @@ -991,20 +991,20 @@ stdlib_overflow(void *arg) result = ~t->result; if (useBuiltin) { - status = SDL_size_mul_overflow(t->b, t->a, &result); + status = SDL_size_mul_check_overflow(t->b, t->a, &result); } else { - status = (SDL_size_mul_overflow)(t->b, t->a, &result); + status = (SDL_size_mul_check_overflow)(t->b, t->a, &result); } - if (t->status == 0) { - SDLTest_AssertCheck(status == 0, + if (t->status) { + SDLTest_AssertCheck(status, "(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed", t->b, t->a); SDLTest_AssertCheck(result == t->result, "(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT, t->b, t->a, t->result, result); } else { - SDLTest_AssertCheck(status == -1, + SDLTest_AssertCheck(!status, "(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail", t->b, t->a); } @@ -1012,24 +1012,24 @@ stdlib_overflow(void *arg) for (i = 0; i < SDL_arraysize(additions); i++) { const overflow_test *t = &additions[i]; - int status; + SDL_bool status; size_t result = ~t->result; if (useBuiltin) { - status = SDL_size_add_overflow(t->a, t->b, &result); + status = SDL_size_add_check_overflow(t->a, t->b, &result); } else { - status = (SDL_size_add_overflow)(t->a, t->b, &result); + status = (SDL_size_add_check_overflow)(t->a, t->b, &result); } - if (t->status == 0) { - SDLTest_AssertCheck(status == 0, + if (t->status) { + SDLTest_AssertCheck(status, "(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed", t->a, t->b); SDLTest_AssertCheck(result == t->result, "(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT, t->a, t->b, t->result, result); } else { - SDLTest_AssertCheck(status == -1, + SDLTest_AssertCheck(!status, "(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail", t->a, t->b); } @@ -1041,20 +1041,20 @@ stdlib_overflow(void *arg) result = ~t->result; if (useBuiltin) { - status = SDL_size_add_overflow(t->b, t->a, &result); + status = SDL_size_add_check_overflow(t->b, t->a, &result); } else { - status = (SDL_size_add_overflow)(t->b, t->a, &result); + status = (SDL_size_add_check_overflow)(t->b, t->a, &result); } - if (t->status == 0) { - SDLTest_AssertCheck(status == 0, + if (t->status) { + SDLTest_AssertCheck(status, "(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed", t->b, t->a); SDLTest_AssertCheck(result == t->result, "(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT, t->b, t->a, t->result, result); } else { - SDLTest_AssertCheck(status == -1, + SDLTest_AssertCheck(!status, "(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail", t->b, t->a); }