When I run my code, I get "Run-Time Check Failure #2 - Stack around the variable 'string' was corrupted."
I have looked everywhere in my code for a source of this error, and I can't find one, I've also looked where a buffer overrun could occur.
The variable string is supposed to be set to ""developer" set to "0.0"", but instead for some reason is't being set to:
"command "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "and "a...
Here is the code that deals with 'string':
//The error is coming from here:
void Con_Printf(const char *format, ...)
{
va_list argptr;
char string[1024];
va_start (argptr, format);
vsprintf (string, format,argptr);
va_end (format);
Con_AddLine (string);
}
void Con_AddLine(const char *string)
{
int len;
int i;
if(con_linecount >= MAX_CONSOLE_LINES)
con_linecount = 0;
len = strlen(string)+1;
if(len > 101)
return;
for(i = 0; i < strlen(string); i++)
con_lines[con_linecount][i] = string[i];
con_linecount++;
}
//con_lines is an array of char * and they are all malloc'd
And here is where all those con_* variables are declared and initialized:
cvar_t developer = {"developer", "1.0", true, true};
cvar_t developer_always_log = {"developer_always_log", "1.0", true};
static char *con_lines[MAX_CONSOLE_LINES];
static int con_linecount;
static gboolean con_visible;
static gboolean con_initialized;
void Con_Init(void)
{
int i;
for(i = 0; i < MAX_CONSOLE_LINES; i++)
con_lines[i] = malloc(sizeof(char)*101);
con_linecount = 0;
con_visible = developer.value;
con_initialized = true;
Con_Printf ("Console: Init ()\n");
}
At the time of the crash, format (in Con_Printf) = "\"%s\" set to \"%f\""