Jump to content


Better va()...


Recommended Posts

char	* QDECL va2( char *format, ... ) {
va_list		argptr;
#define	MAX_VA_STRING	32000
static char		temp_buffer[MAX_VA_STRING];
static char		string[MAX_VA_STRING];	// in case va is called by nested functions
static int		index = 0;
char	*buf;
int len;

va_start (argptr, format);
vsprintf (temp_buffer, format,argptr);
va_end (argptr);

if ((len = strlen(temp_buffer)) >= MAX_VA_STRING) {
	Com_Error( ERR_DROP, "Attempted to overrun string in call to va2()\n" );

if (len + index >= MAX_VA_STRING-1) {
	index = 0;

buf = &string[index];
memcpy( buf, temp_buffer, len+1 );

index += len + 1;

return buf;


modified this to be a circular list, to further prevent stepping on/using

previous strings


dont overwrite the va in q_shared.c as its used by the engine and u cannot modify it :)

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...