Fix bug 1560 - SDL_RWFromConstMem write operation returns -1 but should return 0.
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Tue, 12 Mar 2013 09:10:37 -0700
changeset 6996bc0fd5bced25
parent 6995 7c87aa0a189f
child 6997 0f91d1be17a4
Fix bug 1560 - SDL_RWFromConstMem write operation returns -1 but should return 0.
include/SDL_rwops.h
src/file/SDL_rwops.c
test/testautomation_rwops.c
     1.1 --- a/include/SDL_rwops.h	Sun Mar 10 21:10:10 2013 -0700
     1.2 +++ b/include/SDL_rwops.h	Tue Mar 12 09:10:37 2013 -0700
     1.3 @@ -54,7 +54,7 @@
     1.4       *  Seek to \c offset relative to \c whence, one of stdio's whence values:
     1.5       *  RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
     1.6       *  
     1.7 -     *  \return the final offset in the data stream.
     1.8 +     *  \return the final offset in the data stream, or -1 on error.
     1.9       */
    1.10      Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
    1.11                               int whence);
     2.1 --- a/src/file/SDL_rwops.c	Sun Mar 10 21:10:10 2013 -0700
     2.2 +++ b/src/file/SDL_rwops.c	Tue Mar 12 09:10:37 2013 -0700
     2.3 @@ -451,7 +451,7 @@
     2.4  mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num)
     2.5  {
     2.6      SDL_SetError("Can't write to read-only memory");
     2.7 -    return (-1);
     2.8 +    return (0);
     2.9  }
    2.10  
    2.11  static int SDLCALL
     3.1 --- a/test/testautomation_rwops.c	Sun Mar 10 21:10:10 2013 -0700
     3.2 +++ b/test/testautomation_rwops.c	Tue Mar 12 09:10:37 2013 -0700
     3.3 @@ -78,6 +78,7 @@
     3.4  {
     3.5     char buf[sizeof(RWopsHelloWorldTestString)];
     3.6     Sint64 i;
     3.7 +   size_t s;
     3.8     int seekPos = SDLTest_RandomIntegerInRange(4, 8);
     3.9  
    3.10     /* Clear buffer */
    3.11 @@ -89,13 +90,13 @@
    3.12     SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
    3.13  
    3.14     /* Test write. */
    3.15 -   i = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
    3.16 +   s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
    3.17     SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
    3.18     if (write) {
    3.19 -		SDLTest_AssertCheck(i == (Sint64)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", i);
    3.20 +		SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", s);
    3.21     }
    3.22     else {
    3.23 -		SDLTest_AssertCheck(i != (Sint64)1, "Verify result of writing with SDL_RWwrite, expected !=1, got %i", i);
    3.24 +		SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", s);
    3.25     }
    3.26  
    3.27     /* Test seek to random position */
    3.28 @@ -109,13 +110,13 @@
    3.29     SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
    3.30  
    3.31     /* Test read */
    3.32 -   i = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
    3.33 +   s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
    3.34     SDLTest_AssertPass("Call to SDL_RWread succeeded");
    3.35     SDLTest_AssertCheck(
    3.36 -	   i == (Sint64)(sizeof(RWopsHelloWorldTestString)-1), 
    3.37 +	   s == (size_t)(sizeof(RWopsHelloWorldTestString)-1), 
    3.38  	   "Verify result from SDL_RWread, expected %i, got %i",
    3.39  	   sizeof(RWopsHelloWorldTestString)-1,
    3.40 -	   i);
    3.41 +	   s);
    3.42     SDLTest_AssertCheck(
    3.43  	   SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0, 
    3.44  	   "Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);