From 70e125ba8ef21813c34bb258366a4420e7f52327 Mon Sep 17 00:00:00 2001
From: alistanis <[EMAIL REDACTED]>
Date: Thu, 24 Sep 2026 12:38:48 -0400
Subject: [PATCH] Initialize constant memory stream size
Preserve the supplied size when creating a constant memory stream so lazy
properties report the correct buffer size. Extend the existing constant
memory test to check that property.
---
src/io/SDL_iostream.c | 1 +
test/testautomation_iostream.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/src/io/SDL_iostream.c b/src/io/SDL_iostream.c
index 3382201b0476e..d8a152ed9b76b 100644
--- a/src/io/SDL_iostream.c
+++ b/src/io/SDL_iostream.c
@@ -1253,6 +1253,7 @@ SDL_IOStream *SDL_IOFromConstMem(const void *mem, size_t size)
iodata->base = (Uint8 *)mem;
iodata->here = iodata->base;
iodata->stop = iodata->base + size;
+ iodata->size = size;
SDL_IOStream *iostr = SDL_OpenIO(&iface, iodata);
if (!iostr) {
diff --git a/test/testautomation_iostream.c b/test/testautomation_iostream.c
index 240aaf9f0d457..45d60771e81bb 100644
--- a/test/testautomation_iostream.c
+++ b/test/testautomation_iostream.c
@@ -385,6 +385,7 @@ static int SDLCALL iostrm_testMem(void *arg)
static int SDLCALL iostrm_testConstMem(void *arg)
{
SDL_IOStream *rw;
+ SDL_PropertiesID props;
int result;
/* Open handle */
@@ -400,6 +401,11 @@ static int SDLCALL iostrm_testConstMem(void *arg)
/* Run generic tests */
testGenericIOStreamValidations(rw, false);
+ /* Verify properties preserve the supplied buffer size. */
+ props = SDL_GetIOProperties(rw);
+ SDLTest_AssertCheck(props != 0, "Get constant memory stream properties");
+ SDLTest_AssertCheck(SDL_GetNumberProperty(props, SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER, -1) == (Sint64)(sizeof(IOStreamHelloWorldCompString) - 1), "Verify memory size property matches the supplied buffer size");
+
/* Close handle */
result = SDL_CloseIO(rw);
SDLTest_AssertPass("Call to SDL_CloseIO() succeeded");