From 3a362690c5ebb8cb3c9bb49e46f47b749e143e85 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 8 Aug 2023 00:17:32 -0700
Subject: [PATCH] Fixed potential divide by zero (thanks @sezero!)
---
src/sdl2_compat.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 4fa9680..505a089 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -1812,14 +1812,20 @@ RWops3to2_seek(SDL2_RWops *rwops2, Sint64 offset, int whence)
static size_t SDLCALL
RWops3to2_read(SDL2_RWops *rwops2, void *ptr, size_t size, size_t maxnum)
{
- size_t count = SDL3_RWread(rwops2->hidden.sdl3.rwops, ptr, (size * maxnum)) / size;
+ size_t count = 0;
+ if (size > 0 && maxnum > 0) {
+ count = SDL3_RWread(rwops2->hidden.sdl3.rwops, ptr, (size * maxnum)) / size;
+ }
return count;
}
static size_t SDLCALL
RWops3to2_write(SDL2_RWops *rwops2, const void *ptr, size_t size, size_t maxnum)
{
- size_t count = SDL3_RWwrite(rwops2->hidden.sdl3.rwops, ptr, (size * maxnum)) / size;
+ size_t count = 0;
+ if (size > 0 && maxnum > 0) {
+ count = SDL3_RWwrite(rwops2->hidden.sdl3.rwops, ptr, (size * maxnum)) / size;
+ }
return count;
}