Fix bug 1560 - SDL_RWFromConstMem write operation returns -1 but should return 0.
This commit is contained in:
parent
f25403ba28
commit
6a2bff0cd1
3 changed files with 9 additions and 8 deletions
|
@ -54,7 +54,7 @@ typedef struct SDL_RWops
|
||||||
* Seek to \c offset relative to \c whence, one of stdio's whence values:
|
* Seek to \c offset relative to \c whence, one of stdio's whence values:
|
||||||
* RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
|
* RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
|
||||||
*
|
*
|
||||||
* \return the final offset in the data stream.
|
* \return the final offset in the data stream, or -1 on error.
|
||||||
*/
|
*/
|
||||||
Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
|
Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
|
||||||
int whence);
|
int whence);
|
||||||
|
|
|
@ -451,7 +451,7 @@ static size_t SDLCALL
|
||||||
mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num)
|
mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num)
|
||||||
{
|
{
|
||||||
SDL_SetError("Can't write to read-only memory");
|
SDL_SetError("Can't write to read-only memory");
|
||||||
return (-1);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int SDLCALL
|
static int SDLCALL
|
||||||
|
|
|
@ -78,6 +78,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||||
{
|
{
|
||||||
char buf[sizeof(RWopsHelloWorldTestString)];
|
char buf[sizeof(RWopsHelloWorldTestString)];
|
||||||
Sint64 i;
|
Sint64 i;
|
||||||
|
size_t s;
|
||||||
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
|
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
|
||||||
|
|
||||||
/* Clear buffer */
|
/* Clear buffer */
|
||||||
|
@ -89,13 +90,13 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||||
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
|
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
|
||||||
|
|
||||||
/* Test write. */
|
/* Test write. */
|
||||||
i = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
|
s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
|
||||||
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
|
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
|
||||||
if (write) {
|
if (write) {
|
||||||
SDLTest_AssertCheck(i == (Sint64)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", i);
|
SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", s);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SDLTest_AssertCheck(i != (Sint64)1, "Verify result of writing with SDL_RWwrite, expected !=1, got %i", i);
|
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test seek to random position */
|
/* Test seek to random position */
|
||||||
|
@ -109,13 +110,13 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||||
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
|
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
|
||||||
|
|
||||||
/* Test read */
|
/* Test read */
|
||||||
i = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
|
s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
|
||||||
SDLTest_AssertPass("Call to SDL_RWread succeeded");
|
SDLTest_AssertPass("Call to SDL_RWread succeeded");
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-1),
|
s == (size_t)(sizeof(RWopsHelloWorldTestString)-1),
|
||||||
"Verify result from SDL_RWread, expected %i, got %i",
|
"Verify result from SDL_RWread, expected %i, got %i",
|
||||||
sizeof(RWopsHelloWorldTestString)-1,
|
sizeof(RWopsHelloWorldTestString)-1,
|
||||||
i);
|
s);
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0,
|
SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0,
|
||||||
"Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);
|
"Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue