We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1560

Summary: SDL_RWFromConstMem write operation returns -1 but should return 0.
Product: SDL Reporter: Philipp Wiesemann <philipp.wiesemann>
Component: fileAssignee: Andreas Schiffler <aschiffler>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2 CC: aschiffler
Version: HG 2.0   
Hardware: All   
OS: All   

Description Philipp Wiesemann 2012-08-01 14:07:02 UTC
Hello,

in src/file/SDL_rwops.c (HG) a SDL_RWops created with SDL_RWFromConstMem() uses mem_writeconst() which always returns -1. According to the contract for write operations in SDL_rwops.h it should return 0.

Also -1 is returned as size_t which is unsigned (most of the time).

Another thing which I see as a minor documentation problem is that according to SDL_rwops.h seek operations return the offset but the used stdio_seek() and windows_file_seek() may return -1.
Comment 1 Andreas Schiffler 2013-03-12 11:51:33 UTC
Assigning to myself for fixing and adding test coverage.
Comment 2 Andreas Schiffler 2013-03-12 12:13:27 UTC
Fixed: http://hg.libsdl.org/SDL/rev/bc0fd5bced25
Validation:
$ ./testautomation --filter rwops_testConstMem
INFO:  03/12/13 17:11:15: ----- Test Case 9.3: 'rwops_testConstMem' started
INFO:  03/12/13 17:11:15: Test Description: 'Tests opening from (const) memory'
INFO:  03/12/13 17:11:15: Test Iteration 1: execKey 2631047441197714481
INFO:  03/12/13 17:11:15: Assert 'Verify creation of file 'rwops_read' returned non NULL handle': Passed
INFO:  03/12/13 17:11:15: Assert 'Verify number of written bytes, expected 12, got 12': Passed
INFO:  03/12/13 17:11:15: Assert 'Verify result from fclose, expected 0, got 0': Passed
INFO:  03/12/13 17:11:15: Assert 'Creation of test file completed': Pass
INFO:  03/12/13 17:11:15: Assert 'Call to SDL_RWFromConstMem() succeeded': Pass
INFO:  03/12/13 17:11:15: Assert 'Verify opening memory with SDL_RWFromConstMem does not return NULL': Passed
INFO:  03/12/13 17:11:15: Assert 'Call to SDL_RWseek succeeded': Pass
INFO:  03/12/13 17:11:15: Assert 'Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got 0': Passed
INFO:  03/12/13 17:11:15: Assert 'Call to SDL_RWwrite succeeded': Pass
INFO:  03/12/13 17:11:15: Assert 'Verify result of writing with SDL_RWwrite, expected: 0, got 0': Passed
INFO:  03/12/13 17:11:15: Assert 'Call to SDL_RWseek succeeded': Pass
INFO:  03/12/13 17:11:15: Assert 'Verify seek to 5 with SDL_RWseek (RW_SEEK_SET), expected 5, got 5': Passed
INFO:  03/12/13 17:11:15: Assert 'Call to SDL_RWseek succeeded': Pass
INFO:  03/12/13 17:11:15: Assert 'Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got 0': Passed
INFO:  03/12/13 17:11:15: Assert 'Call to SDL_RWread succeeded': Pass
INFO:  03/12/13 17:11:15: Assert 'Verify result from SDL_RWread, expected 12, got 12': Passed
INFO:  03/12/13 17:11:15: Assert 'Verify read bytes match expected string, expected 'Hello World!', got 'Hello World!'': Passed
INFO:  03/12/13 17:11:15: Assert 'Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded': Pass
INFO:  03/12/13 17:11:15: Assert 'Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected 8, got 8': Passed
INFO:  03/12/13 17:11:15: Assert 'Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded': Pass
INFO:  03/12/13 17:11:15: Assert 'Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected 11, got 11': Passed
INFO:  03/12/13 17:11:15: Assert 'Call to SDL_RWclose() succeeded': Pass
INFO:  03/12/13 17:11:15: Assert 'Verify result from remove(rwops_read), expected 0, got 0': Passed
INFO:  03/12/13 17:11:15: Assert 'Cleanup of test files completed': Pass
INFO:  03/12/13 17:11:15: Fuzzer invocations: 1
INFO:  03/12/13 17:11:15: Assert Summary: Total=24 Passed=24 Failed=0
INFO:  03/12/13 17:11:15: Total Test runtime: 0.0 sec
INFO:  03/12/13 17:11:15: >>> Test 'rwops_testConstMem': Passed