Bug 5935 - QVM memset and memcpy return NULL
Status: NEW
Alias: None
Product: ioquake3
Classification: Unclassified
Component: Misc
Version: GIT MASTER
Hardware: All All
: P3 trivial
Assignee: Zachary J. Slater
QA Contact: ioquake3 bugzilla mailing list
URL:
Depends on:
Blocks:
 
Reported: 2013-05-07 13:16 EDT by Zack Middleton
Modified: 2015-02-12 06:03:39 EST
1 user (show)

See Also:


Attachments
Fix QVM memset and memcpy return values (1.38 KB, patch)
2013-05-07 13:21 EDT, Zack Middleton

Description Zack Middleton 2013-05-07 13:16:09 EDT
QVM memset and memcpy return NULL, but should return first argument (like strncpy). However, fixing this will cause mods that use the return to be incompatible with vanilla q3 and past ioq3 versions.

strncpy was returning incorrect non-zero value in vanilla q3 and fixed in ioq3, so might be similar issue of mod depending on it not working on vanilla q3.

Should they be fixed or left as is?

Issue is in CL_CgameSystemCalls, CL_UISystemCalls, and SV_GameSystemCalls.
Comment 1 Zack Middleton 2013-05-07 13:21:58 EDT
Created attachment 3348 [details]
Fix QVM memset and memcpy return values
Comment 2 Simon McVittie 2015-02-12 06:03:39 EST
Instead of changing the behaviour of syscalls -101 and -102, perhaps it would be better to change their names to trap_memset0 and trap_memcpy0, and change bg_lib.h like this?

// *_syscalls.asm --------------------------------------------------
// Like ISO C memset, but returns NULL instead of dest
equ trap_memset0 -101
// Like ISO C memcpy, but returns NULL instead of dest
equ trap_memcpy0 -102

// bg_lib.h --------------------------------------------------------
void *trap_memset0( void *dest, int c, size_t count );
void *trap_memcpy0( void *dest, const void *src, size_t count );

#define memset(dest, c, count) (trap_memset0(dest, c, count), dest)
#define memcpy(dest, src, count) (trap_memcpy0(dest, src, count), dest)

That way, any VMs compiled with an old bg_lib.h (mods are expected to supply their own copy, right?) will get the result they expects, and any VMs compiled with a new bg_lib.h (notably ioquake3's own game/cgame/ui) will get the result *they* expect, consistent with what they'd get as native code.