int c, track;
char name[MAX_OSPATH];
char vabuf[1024];
+ int vabuf_len;
c = Cmd_Argc(cmd);
if (c != 2 && c != 3 && c != 4)
// start the map up
if (c > 2)
- Cmd_ExecuteString ( cmd, va(vabuf, sizeof(vabuf), "map %s", Cmd_Argv(cmd, 2)), src_local, false);
+ {
+ vabuf_len = dpsnprintf(vabuf, sizeof(vabuf), "map %s", Cmd_Argv(cmd, 2));
+ Cmd_ExecuteString(cmd, vabuf, vabuf_len, src_local, false);
+ }
// open the demo file
Con_Printf("recording to %s.\n", name);
qbool qwplayerupdatereceived;
qbool strip_pqc;
char vabuf[1024];
+ size_t cl_readstring_len;
// LadyHavoc: moved demo message writing from before the packet parse to
// after the packet parse so that CL_Stop_f can be called by cl_autodemo
case qw_svc_print:
i = MSG_ReadByte(&cl_message);
- temp = MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring));
+ cl_readstring_len = MSG_ReadString_len(&cl_message, cl_readstring, sizeof(cl_readstring));
+ temp = cl_readstring;
if (CL_ExaminePrintString(temp)) // look for anything interesting like player IP addresses or ping reports
{
if (i == 3) // chat
- CSQC_AddPrintText(va(vabuf, sizeof(vabuf), "\1%s", temp)); //[515]: csqc
+ {
+ cl_readstring_len = dpsnprintf(vabuf, sizeof(vabuf), "\1%s", temp);
+ CSQC_AddPrintText(vabuf, cl_readstring_len); //[515]: csqc
+ }
else
- CSQC_AddPrintText(temp);
+ CSQC_AddPrintText(temp, cl_readstring_len);
}
break;
case qw_svc_centerprint:
- CL_VM_Parse_CenterPrint(MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring))); //[515]: csqc
+ cl_readstring_len = MSG_ReadString_len(&cl_message, cl_readstring, sizeof(cl_readstring));
+ CL_VM_Parse_CenterPrint(cl_readstring, cl_readstring_len); //[515]: csqc
break;
case qw_svc_stufftext:
- CL_VM_Parse_StuffCmd(MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring))); //[515]: csqc
+ cl_readstring_len = MSG_ReadString_len(&cl_message, cl_readstring, sizeof(cl_readstring));
+ CL_VM_Parse_StuffCmd(cl_readstring, cl_readstring_len); //[515]: csqc
break;
case qw_svc_damage:
break;
case qw_svc_sellscreen:
- Cmd_ExecuteString(cmd_local, "help", src_local, true);
+ Cmd_ExecuteString(cmd_local, "help", 4, src_local, true);
break;
case qw_svc_smallkick:
break;
case svc_print:
- temp = MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring));
+ cl_readstring_len = MSG_ReadString_len(&cl_message, cl_readstring, sizeof(cl_readstring));
+ temp = cl_readstring;
if (CL_ExaminePrintString(temp)) // look for anything interesting like player IP addresses or ping reports
- CSQC_AddPrintText(temp); //[515]: csqc
+ CSQC_AddPrintText(temp, cl_readstring_len); //[515]: csqc
break;
case svc_centerprint:
- CL_VM_Parse_CenterPrint(MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring))); //[515]: csqc
+ cl_readstring_len = MSG_ReadString_len(&cl_message, cl_readstring, sizeof(cl_readstring));
+ CL_VM_Parse_CenterPrint(cl_readstring, cl_readstring_len); //[515]: csqc
break;
case svc_stufftext:
- temp = MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring));
+ cl_readstring_len = MSG_ReadString_len(&cl_message, cl_readstring, sizeof(cl_readstring));
+ temp = cl_readstring;
/* if(utf8_enable.integer)
{
strip_pqc = true;
if(*temp == 0x01)
{
++temp;
+ --cl_readstring_len;
while(*temp >= 0x01 && *temp <= 0x1F)
+ {
++temp;
+ --cl_readstring_len;
+ }
}
}
- CL_VM_Parse_StuffCmd(temp); //[515]: csqc
+ CL_VM_Parse_StuffCmd(temp, cl_readstring_len); //[515]: csqc
break;
case svc_damage:
break;
case svc_sellscreen:
- Cmd_ExecuteString(cmd_local, "help", src_local, true);
+ Cmd_ExecuteString(cmd_local, "help", 4, src_local, true);
break;
case svc_hidelmp:
if (gamemode == GAME_TENEBRAE)
qbool csqc_usecsqclistener;
matrix4x4_t csqc_listenermatrix;
char csqc_printtextbuf[MAX_INPUTLINE];
+ size_t csqc_printtextbuf_len; ///< strlen
// collision culling data
world_t world;
{
int i;
char t[17];
+ size_t t_len;
VM_SAFEPARMCOUNT(1, VM_CL_getstats);
i = (int)PRVM_G_FLOAT(OFS_PARM0);
if(i < 0 || i > MAX_CL_STATS-4)
VM_Warning(prog, "VM_CL_getstats: index>MAX_CL_STATS-4 or index<0\n");
return;
}
- dp_strlcpy(t, (char*)&cl.stats[i], sizeof(t));
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, t);
+ t_len = dp_strlcpy(t, (char*)&cl.stats[i], sizeof(t));
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, t, t_len);
}
//#333 void(entity e, float mdlindex) setmodelindex (EXT_CSQC)
//#348 string(float playernum, string keyname) getplayerkeyvalue (EXT_CSQC)
static void VM_CL_getplayerkey (prvm_prog_t *prog)
{
- int i;
- char t[128];
- const char *c;
+ int i;
+ char t[128];
+ size_t t_len;
+ const char *c;
VM_SAFEPARMCOUNT(2, VM_CL_getplayerkey);
t[0] = 0;
if(!strcasecmp(c, "name"))
- dp_strlcpy(t, cl.scores[i].name, sizeof(t));
+ t_len = dp_strlcpy(t, cl.scores[i].name, sizeof(t));
else
if(!strcasecmp(c, "frags"))
- dpsnprintf(t, sizeof(t), "%i", cl.scores[i].frags);
+ t_len = dpsnprintf(t, sizeof(t), "%i", cl.scores[i].frags);
else
if(!strcasecmp(c, "ping"))
- dpsnprintf(t, sizeof(t), "%i", cl.scores[i].qw_ping);
+ t_len = dpsnprintf(t, sizeof(t), "%i", cl.scores[i].qw_ping);
else
if(!strcasecmp(c, "pl"))
- dpsnprintf(t, sizeof(t), "%i", cl.scores[i].qw_packetloss);
+ t_len = dpsnprintf(t, sizeof(t), "%i", cl.scores[i].qw_packetloss);
else
if(!strcasecmp(c, "movementloss"))
- dpsnprintf(t, sizeof(t), "%i", cl.scores[i].qw_movementloss);
+ t_len = dpsnprintf(t, sizeof(t), "%i", cl.scores[i].qw_movementloss);
else
if(!strcasecmp(c, "entertime"))
- dpsnprintf(t, sizeof(t), "%f", cl.scores[i].qw_entertime);
+ t_len = dpsnprintf(t, sizeof(t), "%f", cl.scores[i].qw_entertime);
else
if(!strcasecmp(c, "colors"))
- dpsnprintf(t, sizeof(t), "%i", cl.scores[i].colors);
+ t_len = dpsnprintf(t, sizeof(t), "%i", cl.scores[i].colors);
else
if(!strcasecmp(c, "topcolor"))
- dpsnprintf(t, sizeof(t), "%i", cl.scores[i].colors & 0xf0);
+ t_len = dpsnprintf(t, sizeof(t), "%i", cl.scores[i].colors & 0xf0);
else
if(!strcasecmp(c, "bottomcolor"))
- dpsnprintf(t, sizeof(t), "%i", (cl.scores[i].colors &15)<<4);
+ t_len = dpsnprintf(t, sizeof(t), "%i", (cl.scores[i].colors &15)<<4);
else
if(!strcasecmp(c, "viewentity"))
- dpsnprintf(t, sizeof(t), "%i", i+1);
+ t_len = dpsnprintf(t, sizeof(t), "%i", i+1);
if(!t[0])
return;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, t);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, t, t_len);
}
//#351 void(vector origin, vector forward, vector right, vector up) SetListener (EXT_CSQC)
//#366 string() readstring (EXT_CSQC)
static void VM_CL_ReadString (prvm_prog_t *prog)
{
+ size_t cl_readstring_len;
+
VM_SAFEPARMCOUNT(0, VM_CL_ReadString);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)));
+ cl_readstring_len = MSG_ReadString_len(&cl_message, cl_readstring, sizeof(cl_readstring));
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cl_readstring, cl_readstring_len);
}
//#367 float() readfloat (EXT_CSQC)
static void VM_CL_ReadPicture (prvm_prog_t *prog)
{
const char *name;
+ size_t name_len;
unsigned char *data;
unsigned char *buf;
unsigned short size;
VM_SAFEPARMCOUNT(0, VM_CL_ReadPicture);
- name = MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring));
+ name_len = MSG_ReadString_len(&cl_message, cl_readstring, sizeof(cl_readstring));
+ name = cl_readstring;
size = (unsigned short) MSG_ReadShort(&cl_message);
// check if a texture of that name exists
}
}
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, name);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, name, name_len);
}
//////////////////////////////////////////////////////////
Matrix4x4_ToVectors(&tag_localmatrix, forward, left, up, origin);
PRVM_clientglobalfloat(gettaginfo_parent) = parentindex;
- PRVM_clientglobalstring(gettaginfo_name) = tagname ? PRVM_SetTempString(prog, tagname) : 0;
+ PRVM_clientglobalstring(gettaginfo_name) = tagname ? PRVM_SetTempString(prog, tagname, strlen(tagname)) : 0;
VectorCopy(forward, PRVM_clientglobalvector(gettaginfo_forward));
VectorScale(left, -1, PRVM_clientglobalvector(gettaginfo_right));
VectorCopy(up, PRVM_clientglobalvector(gettaginfo_up));
char string[VM_TEMPSTRING_MAXSIZE];
VM_SAFEPARMCOUNT(1, VM_CL_serverkey);
InfoString_GetValue(cl.qw_serverinfo, PRVM_G_STRING(OFS_PARM0), string, sizeof(string));
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string, strlen(string));
}
/*
return;
if (bonenum < 0 || bonenum >= skeleton->model->num_bones)
return;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, skeleton->model->data_bones[bonenum].name);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, skeleton->model->data_bones[bonenum].name, strlen(skeleton->model->data_bones[bonenum].name));
}
// #267 float(float skel, float bonenum) skel_get_boneparent = #267; // (FTE_CSQC_SKELETONOBJECTS) returns parent num for supplied bonenum, 0 if bonenum has no parent or bone does not exist (returned value is always less than bonenum, you can loop on this)
============
*/
extern qbool prvm_runawaycheck;
-static qbool Cmd_PreprocessString(cmd_state_t *cmd, const char *intext, char *outtext, unsigned maxoutlen, cmd_alias_t *alias );
+static size_t Cmd_PreprocessString(cmd_state_t *cmd, const char *intext, char *outtext, unsigned maxoutlen, cmd_alias_t *alias);
void Cbuf_Execute (cmd_buf_t *cbuf)
{
cmd_input_t *current;
char preprocessed[MAX_INPUTLINE];
+ size_t preprocessed_len;
char *firstchar;
unsigned int i = 0;
firstchar = current->text;
while(*firstchar && ISWHITESPACE(*firstchar))
++firstchar;
- if((strncmp(firstchar, "alias", 5) || !ISWHITESPACE(firstchar[5])) &&
- (strncmp(firstchar, "bind", 4) || !ISWHITESPACE(firstchar[4])) &&
- (strncmp(firstchar, "in_bind", 7) || !ISWHITESPACE(firstchar[7])))
+ if((strncmp(firstchar, "alias", 5) || !ISWHITESPACE(firstchar[5]))
+ && (strncmp(firstchar, "bind", 4) || !ISWHITESPACE(firstchar[4]))
+ && (strncmp(firstchar, "in_bind", 7) || !ISWHITESPACE(firstchar[7])))
{
- if(Cmd_PreprocessString(current->source, current->text, preprocessed, sizeof(preprocessed), NULL ))
- Cmd_ExecuteString(current->source, preprocessed, src_local, false);
+ if((preprocessed_len = Cmd_PreprocessString(current->source, current->text, preprocessed, sizeof(preprocessed), NULL)))
+ Cmd_ExecuteString(current->source, preprocessed, preprocessed_len, src_local, false);
}
else
{
- Cmd_ExecuteString (current->source, current->text, src_local, false);
+ Cmd_ExecuteString(current->source, current->text, current->length, src_local, false);
}
// Recycle memory so using WASD doesn't cause a malloc and free
return varstr;
}
-/*
+/**
Cmd_PreprocessString
Preprocesses strings and replaces $*, $param#, $cvar accordingly. Also strips comments.
+Returns the number of bytes written to *outtext excluding the \0 terminator.
*/
-static qbool Cmd_PreprocessString(cmd_state_t *cmd, const char *intext, char *outtext, unsigned maxoutlen, cmd_alias_t *alias ) {
+static size_t Cmd_PreprocessString(cmd_state_t *cmd, const char *intext, char *outtext, unsigned maxoutlen, cmd_alias_t *alias)
+{
const char *in;
size_t eat, varlen;
unsigned outlen;
// don't crash if there's no room in the outtext buffer
if( maxoutlen == 0 ) {
- return false;
+ return 0;
}
maxoutlen--; // because of \0
{
val = Cmd_GetCvarValue(cmd, in + 1, varlen, alias);
if(!val)
- return false;
+ return 0;
eat = varlen + 2;
}
else
varlen = strspn(in, "#*0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-");
val = Cmd_GetCvarValue(cmd, in, varlen, alias);
if(!val)
- return false;
+ return 0;
eat = varlen;
}
if(val)
else
outtext[outlen++] = *in++;
}
- outtext[outlen] = 0;
- return true;
+ outtext[outlen] = '\0';
+ return outlen;
}
/*
* implement that behavior that doesn't involve an #ifdef, or
* making a mess of hooks.
*/
-qbool Cmd_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src)
+qbool Cmd_Callback(cmd_state_t *cmd, cmd_function_t *func)
{
if (func->function)
func->function(cmd);
return true;
}
-qbool Cmd_CL_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src)
+qbool Cmd_CL_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, size_t textlen, cmd_source_t src)
{
// TODO: Assign these functions to QC commands directly?
if(func->qcfunc)
{
- if(((func->flags & CF_CLIENT) && CL_VM_ConsoleCommand(text)) ||
- ((func->flags & CF_SERVER) && SV_VM_ConsoleCommand(text)))
+ if(((func->flags & CF_CLIENT) && CL_VM_ConsoleCommand(text, textlen)) ||
+ ((func->flags & CF_SERVER) && SV_VM_ConsoleCommand(text, textlen)))
return true;
if (func->overridden) // If this QC command overrides an engine command,
return true;
}
}
- return Cmd_Callback(cmd, func, text, src);
+ return Cmd_Callback(cmd, func);
}
-qbool Cmd_SV_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src)
+qbool Cmd_SV_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, size_t textlen, cmd_source_t src)
{
if(func->qcfunc && (func->flags & CF_SERVER))
- return SV_VM_ConsoleCommand(text);
+ return SV_VM_ConsoleCommand(text, textlen);
else if (src == src_client)
{
if((func->flags & CF_CHEAT) && !sv_cheats.integer)
FIXME: lookupnoadd the token to speed search?
============
*/
-void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qbool lockmutex)
+void Cmd_ExecuteString(cmd_state_t *cmd, const char *text, size_t textlen, cmd_source_t src, qbool lockmutex)
{
int oldpos;
cmd_function_t *func;
// check functions
for (func = cmd->userdefined->qc_functions; func; func = func->next)
if (!strcasecmp(cmd->argv[0], func->name))
- if(cmd->Handle(cmd, func, text, src))
+ if(cmd->Handle(cmd, func, text, textlen, src))
goto functions_done;
for (func = cmd->engine_functions; func; func=func->next)
if (!strcasecmp (cmd->argv[0], func->name))
- if(cmd->Handle(cmd, func, text, src))
+ if(cmd->Handle(cmd, func, text, textlen, src))
goto functions_done;
functions_done:
unsigned cvars_flagsmask; // which CVAR_* flags should be visible to this interpreter? (CF_CLIENT | CF_SERVER, or just CF_SERVER)
unsigned cmd_flagsmask; // cmd flags that identify this interpreter
- qbool (*Handle)(struct cmd_state_s *, struct cmd_function_s *, const char *, enum cmd_source_s);
+ qbool (*Handle)(struct cmd_state_s *, struct cmd_function_s *, const char *, size_t, enum cmd_source_s);
}
cmd_state_t;
-qbool Cmd_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src);
-qbool Cmd_CL_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src);
-qbool Cmd_SV_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, cmd_source_t src);
+qbool Cmd_Callback(cmd_state_t *cmd, cmd_function_t *func);
+qbool Cmd_CL_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, size_t textlen, cmd_source_t src);
+qbool Cmd_SV_Callback(cmd_state_t *cmd, cmd_function_t *func, const char *text, size_t textlen, cmd_source_t src);
typedef struct cmd_input_s
{
/// Parses a single line of text into arguments and tries to execute it.
/// The text can come from the command buffer, a remote client, or stdin.
-void Cmd_ExecuteString (cmd_state_t *cmd, const char *text, cmd_source_t src, qbool lockmutex);
+void Cmd_ExecuteString(cmd_state_t *cmd, const char *text, size_t textlen, cmd_source_t src, qbool lockmutex);
/// quotes a string so that it can be used as a command argument again;
/// quoteset is a string that contains one or more of ", \, $ and specifies
while ((c = MSG_ReadByte(sb)) > 0)
if (l < maxstring - 1)
string[l++] = c;
- string[l] = 0;
+ string[l] = '\0';
return string;
}
+size_t MSG_ReadString_len (sizebuf_t *sb, char *string, size_t maxstring)
+{
+ int c;
+ size_t l = 0;
+ // read string into sbfer, but only store as many characters as will fit
+ while ((c = MSG_ReadByte(sb)) > 0)
+ if (l < maxstring - 1)
+ string[l++] = c;
+ string[l] = '\0';
+ return l;
+}
int MSG_ReadBytes (sizebuf_t *sb, int numbytes, unsigned char *out)
{
cvar_t cl_playerskin = {CF_CLIENT | CF_SERVER | CF_USERINFO | CF_ARCHIVE, "playerskin", "", "current player skin in Nexuiz/Xonotic"};
char com_token[MAX_INPUTLINE];
+unsigned com_token_len;
//===========================================================================
COM_ParseToken_Simple
Parse a token out of a string
+Writes the token and its strlen to the com_token and com_token_len globals.
==============
*/
int COM_ParseToken_Simple(const char **datapointer, qbool returnnewline, qbool parsebackslash, qbool parsecomments)
int c;
const char *data = *datapointer;
- len = 0;
- com_token[0] = 0;
+ com_token_len = len = 0;
+ com_token[0] = '\0';
if (!data)
{
if (len < (int)sizeof(com_token) - 1)
com_token[len++] = c;
}
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
if (*data == '\"')
data++;
*datapointer = data;
{
// translate Mac line ending to UNIX
com_token[len++] = '\n';data++;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
return true;
}
{
// single character
com_token[len++] = *data++;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
return true;
}
for (;!ISWHITESPACE(*data);data++)
if (len < (int)sizeof(com_token) - 1)
com_token[len++] = *data;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
return true;
}
COM_ParseToken_QuakeC
Parse a token out of a string
+Writes the token and its strlen to the com_token and com_token_len globals.
==============
*/
int COM_ParseToken_QuakeC(const char **datapointer, qbool returnnewline)
int c;
const char *data = *datapointer;
- len = 0;
- com_token[0] = 0;
+ com_token_len = len = 0;
+ com_token[0] = '\0';
if (!data)
{
if (len < (int)sizeof(com_token) - 1)
com_token[len++] = c;
}
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
if (*data == quote)
data++;
*datapointer = data;
{
// translate Mac line ending to UNIX
com_token[len++] = '\n';data++;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
return true;
}
{
// single character
com_token[len++] = *data++;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
return true;
}
for (;!ISWHITESPACE(*data) && *data != '{' && *data != '}' && *data != ')' && *data != '(' && *data != ']' && *data != '[' && *data != ':' && *data != ',' && *data != ';';data++)
if (len < (int)sizeof(com_token) - 1)
com_token[len++] = *data;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
return true;
}
COM_ParseToken_VM_Tokenize
Parse a token out of a string
+Writes the token and its strlen to the com_token and com_token_len globals.
==============
*/
int COM_ParseToken_VM_Tokenize(const char **datapointer, qbool returnnewline)
int c;
const char *data = *datapointer;
- len = 0;
- com_token[0] = 0;
+ com_token_len = len = 0;
+ com_token[0] = '\0';
if (!data)
{
if (len < (int)sizeof(com_token) - 1)
com_token[len++] = c;
}
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
if (*data == quote)
data++;
*datapointer = data;
{
// translate Mac line ending to UNIX
com_token[len++] = '\n';data++;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
return true;
}
{
// single character
com_token[len++] = *data++;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
return true;
}
for (;!ISWHITESPACE(*data) && *data != '{' && *data != '}' && *data != ')' && *data != '(' && *data != ']' && *data != '[' && *data != ':' && *data != ',' && *data != ';';data++)
if (len < (int)sizeof(com_token) - 1)
com_token[len++] = *data;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
return true;
}
COM_ParseToken_Console
Parse a token out of a string, behaving like the qwcl console
+Writes the token and its strlen to the com_token and com_token_len globals.
==============
*/
int COM_ParseToken_Console(const char **datapointer)
int len;
const char *data = *datapointer;
- len = 0;
- com_token[0] = 0;
+ com_token_len = len = 0;
+ com_token[0] = '\0';
if (!data)
{
if (len < (int)sizeof(com_token) - 1)
com_token[len++] = *data;
}
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
if (*data == '\"')
data++;
*datapointer = data;
for (;!ISWHITESPACE(*data);data++)
if (len < (int)sizeof(com_token) - 1)
com_token[len++] = *data;
- com_token[len] = 0;
+ com_token[len] = '\0';
+ com_token_len = len;
*datapointer = data;
}
//======================================
-void COM_ToLowerString (const char *in, char *out, size_t size_out)
+size_t COM_ToLowerString(const char *in, char *out, size_t size_out)
{
+ const char *out_start = out;
+
if (size_out == 0)
- return;
+ return 0;
if(utf8_enable.integer)
{
Uchar ch = u8_getchar_utf8_enabled(in, &in);
ch = u8_tolower(ch);
n = u8_fromchar(ch, out, size_out);
+ out += n; // before the break so the return is correct
if(n <= 0)
break;
- out += n;
size_out -= n;
}
- return;
+ return out - out_start;
}
while (*in && size_out > 1)
size_out--;
}
*out = '\0';
+ return out - out_start;
}
-void COM_ToUpperString (const char *in, char *out, size_t size_out)
+size_t COM_ToUpperString(const char *in, char *out, size_t size_out)
{
+ const char *out_start = out;
+
if (size_out == 0)
- return;
+ return 0;
if(utf8_enable.integer)
{
Uchar ch = u8_getchar_utf8_enabled(in, &in);
ch = u8_toupper(ch);
n = u8_fromchar(ch, out, size_out);
+ out += n; // before the break so the return is correct
if(n <= 0)
break;
- out += n;
size_out -= n;
}
- return;
+ return out - out_start;
}
while (*in && size_out > 1)
size_out--;
}
*out = '\0';
+ return out - out_start;
}
int COM_StringBeginsWith(const char *s, const char *match)
If escape_carets is true, the resulting string will be safe for printing. If
escape_carets is false, the function will just strip color codes (for logging
for example).
+Returns the number of bytes written to the *out buffer excluding the \0 terminator.
-If the output buffer size did not suffice for converting, the function returns
-FALSE. Generally, if escape_carets is false, the output buffer needs
+If the output buffer size did not suffice for converting, the function returns 0.
+Generally, if escape_carets is false, the output buffer needs
strlen(str)+1 bytes, and if escape_carets is true, it can need strlen(str)*1.5+2
bytes. In any case, the function makes sure that the resulting string is
zero terminated.
all characters until the zero terminator.
============
*/
-qbool
-COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out, qbool escape_carets)
+size_t COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out, qbool escape_carets)
{
-#define APPEND(ch) do { if(--size_out) { *out++ = (ch); } else { *out++ = 0; return false; } } while(0)
+#define APPEND(ch) do { if(--size_out) { *out++ = (ch); } else { *out++ = 0; return 0; } } while(0)
+
+ const char *out_start = out;
const char *end = size_in ? (in + size_in) : NULL;
+
if(size_out < 1)
- return false;
+ return 0;
for(;;)
{
switch((in == end) ? 0 : *in)
{
case 0:
- *out++ = 0;
- return true;
+ *out = '\0';
+ return out - out_start;
case STRING_COLOR_TAG:
++in;
switch((in == end) ? 0 : *in)
// finish the code by appending another caret when escaping
if(escape_carets)
APPEND(STRING_COLOR_TAG);
- *out++ = 0;
- return true;
+ *out = '\0';
+ return out - out_start;
case STRING_COLOR_TAG: // escaped ^
APPEND(STRING_COLOR_TAG);
// append a ^ twice when escaping
float MSG_ReadLittleFloat (sizebuf_t *sb);
float MSG_ReadBigFloat (sizebuf_t *sb);
char *MSG_ReadString (sizebuf_t *sb, char *string, size_t maxstring);
+/// Same as MSG_ReadString except it returns the number of bytes written to *string excluding the \0 terminator.
+size_t MSG_ReadString_len (sizebuf_t *sb, char *string, size_t maxstring);
int MSG_ReadBytes (sizebuf_t *sb, int numbytes, unsigned char *out);
#define MSG_ReadChar(sb) ((sb)->readcount >= (sb)->cursize ? ((sb)->badread = true, -1) : (signed char)(sb)->data[(sb)->readcount++])
int COM_Wordwrap(const char *string, size_t length, float continuationSize, float maxWidth, COM_WordWidthFunc_t wordWidth, void *passthroughCW, COM_LineProcessorFunc processLine, void *passthroughPL);
extern char com_token[MAX_INPUTLINE];
-
+extern unsigned com_token_len;
int COM_ParseToken_Simple(const char **datapointer, qbool returnnewline, qbool parsebackslash, qbool parsecomments);
int COM_ParseToken_QuakeC(const char **datapointer, qbool returnnewline);
int COM_ParseToken_VM_Tokenize(const char **datapointer, qbool returnnewline);
}
userdirmode_t;
-void COM_ToLowerString (const char *in, char *out, size_t size_out);
-void COM_ToUpperString (const char *in, char *out, size_t size_out);
+/// Returns the number of bytes written to *out excluding the \0 terminator.
+size_t COM_ToLowerString(const char *in, char *out, size_t size_out);
+/// Returns the number of bytes written to *out excluding the \0 terminator.
+size_t COM_ToUpperString(const char *in, char *out, size_t size_out);
int COM_StringBeginsWith(const char *s, const char *match);
-
int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *tokenbuf, int tokenbufsize, const char *commentprefix);
-
size_t COM_StringLengthNoColors(const char *s, size_t size_s, qbool *valid);
-qbool COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out, qbool escape_carets);
-void COM_ToLowerString (const char *in, char *out, size_t size_out);
-void COM_ToUpperString (const char *in, char *out, size_t size_out);
+size_t COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out, qbool escape_carets);
+
#define dp_strlcpy(dst, src, dsize) dp__strlcpy(dst, src, dsize, __func__, __LINE__)
chat_mode = mode;
if(Cmd_Argc(cmd) > 1)
{
- dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args(cmd));
- chat_bufferpos = (unsigned int)strlen(chat_buffer);
+ chat_bufferpos = dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args(cmd));
+ if (chat_bufferpos < 0)
+ chat_bufferpos = 0;
}
}
return true;
}
-qbool CL_VM_ConsoleCommand (const char *text)
+qbool CL_VM_ConsoleCommand(const char *text, size_t textlen)
{
prvm_prog_t *prog = CLVM_prog;
- return PRVM_ConsoleCommand(prog, text, &prog->funcoffsets.CSQC_ConsoleCommand, false, cl.csqc_server2csqcentitynumber[cl.playerentity], cl.time, cl.csqc_loaded, "QC function CSQC_ConsoleCommand is missing");
+ return PRVM_ConsoleCommand(prog, text, textlen, &prog->funcoffsets.CSQC_ConsoleCommand, false, cl.csqc_server2csqcentitynumber[cl.playerentity], cl.time, cl.csqc_loaded, "QC function CSQC_ConsoleCommand is missing");
}
qbool CL_VM_Parse_TempEntity (void)
return r;
}
-void CL_VM_Parse_StuffCmd (const char *msg)
+void CL_VM_Parse_StuffCmd(const char *msg, size_t msg_len)
{
prvm_prog_t *prog = CLVM_prog;
int restorevm_tempstringsbuf_cursize;
int crcflags = csqc_progcrc.flags;
csqc_progcrc.flags &= ~CF_READONLY;
csqc_progsize.flags &= ~CF_READONLY;
- Cmd_ExecuteString(cmd_local, msg, src_local, true);
+ Cmd_ExecuteString(cmd_local, msg, msg_len, src_local, true);
csqc_progcrc.flags = csqc_progsize.flags = crcflags;
return;
}
PRVM_clientglobalfloat(time) = cl.time;
PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
- PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, msg);
+ PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, msg, msg_len);
prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Parse_StuffCmd), "QC function CSQC_Parse_StuffCmd is missing");
prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
}
CSQC_END
}
-static void CL_VM_Parse_Print (const char *msg)
+static void CL_VM_Parse_Print(const char *msg, size_t msg_len)
{
prvm_prog_t *prog = CLVM_prog;
int restorevm_tempstringsbuf_cursize;
PRVM_clientglobalfloat(time) = cl.time;
PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
- PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, msg);
+ PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, msg, msg_len);
prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Parse_Print), "QC function CSQC_Parse_Print is missing");
prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
}
-void CSQC_AddPrintText (const char *msg)
+void CSQC_AddPrintText(const char *msg, size_t msg_len)
{
prvm_prog_t *prog = CLVM_prog;
- size_t i;
+ char *start = cl.csqc_printtextbuf + cl.csqc_printtextbuf_len;
+ size_t writebytes = min(msg_len + 1, MAX_INPUTLINE - cl.csqc_printtextbuf_len);
+
CSQC_BEGIN
if(cl.csqc_loaded && PRVM_clientfunction(CSQC_Parse_Print))
{
- // FIXME: is this bugged?
- i = strlen(msg)-1;
- if(msg[i] != '\n' && msg[i] != '\r')
+ if(msg[msg_len - 1] != '\n' && msg[msg_len - 1] != '\r')
{
- if(strlen(cl.csqc_printtextbuf)+i >= MAX_INPUTLINE)
+ if(cl.csqc_printtextbuf_len + msg_len + 1 >= MAX_INPUTLINE)
{
- CL_VM_Parse_Print(cl.csqc_printtextbuf);
- cl.csqc_printtextbuf[0] = 0;
+ CL_VM_Parse_Print(cl.csqc_printtextbuf, cl.csqc_printtextbuf_len);
+ cl.csqc_printtextbuf[0] = '\0';
+ cl.csqc_printtextbuf_len = 0;
}
else
- dp_strlcat(cl.csqc_printtextbuf, msg, MAX_INPUTLINE);
+ {
+ memcpy(start, msg, writebytes);
+ cl.csqc_printtextbuf_len += msg_len;
+ }
return;
}
- dp_strlcat(cl.csqc_printtextbuf, msg, MAX_INPUTLINE);
- CL_VM_Parse_Print(cl.csqc_printtextbuf);
- cl.csqc_printtextbuf[0] = 0;
+ memcpy(start, msg, writebytes);
+ cl.csqc_printtextbuf_len += msg_len;
+ CL_VM_Parse_Print(cl.csqc_printtextbuf, cl.csqc_printtextbuf_len);
+ cl.csqc_printtextbuf[0] = '\0';
+ cl.csqc_printtextbuf_len = 0;
}
else
Con_Print(msg);
CSQC_END
}
-void CL_VM_Parse_CenterPrint (const char *msg)
+void CL_VM_Parse_CenterPrint(const char *msg, size_t msg_len)
{
prvm_prog_t *prog = CLVM_prog;
int restorevm_tempstringsbuf_cursize;
PRVM_clientglobalfloat(time) = cl.time;
PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
- PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, msg);
+ PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, msg, msg_len);
prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Parse_CenterPrint), "QC function CSQC_Parse_CenterPrint is missing");
prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
}
PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
PRVM_G_FLOAT(OFS_PARM0) = ent;
PRVM_G_FLOAT(OFS_PARM1) = CHAN_ENGINE2USER(channel);
- PRVM_G_INT(OFS_PARM2) = PRVM_SetTempString(prog, cl.sound_name[sound_num] );
+ PRVM_G_INT(OFS_PARM2) = PRVM_SetTempString(prog, cl.sound_name[sound_num], strlen(cl.sound_name[sound_num]));
PRVM_G_FLOAT(OFS_PARM3) = fvolume;
PRVM_G_FLOAT(OFS_PARM4) = attenuation;
VectorCopy(pos, PRVM_G_VECTOR(OFS_PARM5) );
void CL_VM_UpdateIntermissionState(int intermission);
void CL_VM_UpdateShowingScoresState(int showingscores);
qbool CL_VM_InputEvent(int eventtype, float x, float y);
-qbool CL_VM_ConsoleCommand(const char *text);
+qbool CL_VM_ConsoleCommand(const char *text, size_t textlen);
void CL_VM_UpdateDmgGlobals(int dmg_take, int dmg_save, vec3_t dmg_origin);
void CL_VM_UpdateIntermissionState(int intermission);
qbool CL_VM_Event_Sound(int sound_num, float volume, int channel, float attenuation, int ent, vec3_t pos, int flags, float speed);
qbool CL_VM_Parse_TempEntity(void);
-void CL_VM_Parse_StuffCmd(const char *msg);
-void CL_VM_Parse_CenterPrint(const char *msg);
+void CL_VM_Parse_StuffCmd(const char *msg, size_t msg_len);
+void CL_VM_Parse_CenterPrint(const char *msg, size_t msg_len);
int CL_GetPitchSign(prvm_prog_t *prog, prvm_edict_t *ent);
int CL_GetTagMatrix(prvm_prog_t *prog, matrix4x4_t *out, prvm_edict_t *ent, int tagindex, prvm_vec_t *shadingorigin);
void CL_GetEntityMatrix(prvm_prog_t *prog, prvm_edict_t *ent, matrix4x4_t *out, qbool viewmatrix);
void QW_CL_StartUpload(unsigned char *data, int size);
void CSQC_UpdateNetworkTimes(double newtime, double oldtime);
-void CSQC_AddPrintText(const char *msg);
+void CSQC_AddPrintText(const char *msg, size_t msg_len);
void CSQC_ReadEntities(void);
void CSQC_RelinkAllEntities(int drawmask);
void CSQC_RelinkCSQCEntities(void);
if (key == K_ENTER || key == K_KP_ENTER || ascii == 10 || ascii == 13)
{
if(chat_mode < 0)
- Cmd_ExecuteString(cmd, chat_buffer, src_local, true); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
+ Cmd_ExecuteString(cmd, chat_buffer, strlen(chat_buffer), src_local, true); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases!
else
CL_ForwardToServer(va(vabuf, sizeof(vabuf), "%s %s", chat_mode ? "say_team" : "say ", chat_buffer));
{
if (stringbuffersize >= 12)
{
- dpsnprintf(string, stringbuffersize, "local:%d", address->port);
- return 1;
+ return dpsnprintf(string, stringbuffersize, "local:%d", address->port);
}
}
else
if (stringbuffersize >= 6)
{
memcpy(string, "local", 6);
- return 1;
+ return 5;
}
}
break;
{
if (stringbuffersize >= 22)
{
- dpsnprintf(string, stringbuffersize, "%d.%d.%d.%d:%d", a[0], a[1], a[2], a[3], address->port);
- return 1;
+ return dpsnprintf(string, stringbuffersize, "%d.%d.%d.%d:%d", a[0], a[1], a[2], a[3], address->port);
}
}
else
{
if (stringbuffersize >= 16)
{
- dpsnprintf(string, stringbuffersize, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
- return 1;
+ return dpsnprintf(string, stringbuffersize, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
}
}
break;
{
if (stringbuffersize >= 88)
{
- dpsnprintf(string, stringbuffersize, "[%x:%x:%x:%x:%x:%x:%x:%x]:%d", a[0] * 256 + a[1], a[2] * 256 + a[3], a[4] * 256 + a[5], a[6] * 256 + a[7], a[8] * 256 + a[9], a[10] * 256 + a[11], a[12] * 256 + a[13], a[14] * 256 + a[15], address->port);
- return 1;
+ return dpsnprintf(string, stringbuffersize, "[%x:%x:%x:%x:%x:%x:%x:%x]:%d", a[0] * 256 + a[1], a[2] * 256 + a[3], a[4] * 256 + a[5], a[6] * 256 + a[7], a[8] * 256 + a[9], a[10] * 256 + a[11], a[12] * 256 + a[13], a[14] * 256 + a[15], address->port);
}
}
else
{
if (stringbuffersize >= 80)
{
- dpsnprintf(string, stringbuffersize, "%x:%x:%x:%x:%x:%x:%x:%x", a[0] * 256 + a[1], a[2] * 256 + a[3], a[4] * 256 + a[5], a[6] * 256 + a[7], a[8] * 256 + a[9], a[10] * 256 + a[11], a[12] * 256 + a[13], a[14] * 256 + a[15]);
- return 1;
+ return dpsnprintf(string, stringbuffersize, "%x:%x:%x:%x:%x:%x:%x:%x", a[0] * 256 + a[1], a[2] * 256 + a[3], a[4] * 256 + a[5], a[6] * 256 + a[7], a[8] * 256 + a[9], a[10] * 256 + a[11], a[12] * 256 + a[13], a[14] * 256 + a[15]);
}
}
break;
int LHNETADDRESS_FromPort(lhnetaddress_t *address, lhnetaddresstype_t addresstype, int port);
int LHNETADDRESS_FromString(lhnetaddress_t *address, const char *string, int defaultport);
+/// Returns the number of bytes written to *string excluding the \0 terminator.
int LHNETADDRESS_ToString(const lhnetaddress_t *address, char *string, int stringbuffersize, int includeport);
static inline lhnetaddresstype_t LHNETADDRESS_GetAddressType(const lhnetaddress_t *address)
{
void MP_ToggleMenu (int mode);
void MP_Shutdown (void);*/
-qbool MP_ConsoleCommand(const char *text);
+qbool MP_ConsoleCommand(const char *text, size_t textlen);
//
// menu router
NULL
};
-qbool MP_ConsoleCommand(const char *text)
+qbool MP_ConsoleCommand(const char *text, size_t textlen)
{
prvm_prog_t *prog = MVM_prog;
- return PRVM_ConsoleCommand(prog, text, &prog->funcoffsets.GameCommand, false, -1, 0, prog->loaded, "QC function GameCommand is missing");
+ return PRVM_ConsoleCommand(prog, text, textlen, &prog->funcoffsets.GameCommand, false, -1, 0, prog->loaded, "QC function GameCommand is missing");
}
/*
if(nr >= 0 && nr < fs_all_gamedirs_count)
{
if(item == 0)
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, fs_all_gamedirs[nr].name );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, fs_all_gamedirs[nr].name, strlen(fs_all_gamedirs[nr].name));
else if(item == 1)
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, fs_all_gamedirs[nr].description );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, fs_all_gamedirs[nr].description, strlen(fs_all_gamedirs[nr].description));
}
}
switch( field ) {
case SLIF_CNAME:
- dp_strlcpy( mask->info.cname, str, sizeof(mask->info.cname) );
+ mask->info.cname_len = dp_strlcpy(mask->info.cname, str, sizeof(mask->info.cname));
break;
case SLIF_NAME:
- dp_strlcpy( mask->info.name, str, sizeof(mask->info.name) );
+ mask->info.name_len = dp_strlcpy(mask->info.name, str, sizeof(mask->info.name));
break;
case SLIF_QCSTATUS:
- dp_strlcpy( mask->info.qcstatus, str, sizeof(mask->info.qcstatus) );
+ mask->info.qcstatus_len = dp_strlcpy(mask->info.qcstatus, str, sizeof(mask->info.qcstatus));
break;
case SLIF_PLAYERS:
- dp_strlcpy( mask->info.players, str, sizeof(mask->info.players) );
+ mask->info.players_len = dp_strlcpy(mask->info.players, str, sizeof(mask->info.players));
break;
case SLIF_MAP:
- dp_strlcpy( mask->info.map, str, sizeof(mask->info.map) );
+ mask->info.map_len = dp_strlcpy(mask->info.map, str, sizeof(mask->info.map));
break;
case SLIF_MOD:
- dp_strlcpy( mask->info.mod, str, sizeof(mask->info.mod) );
+ mask->info.mod_len = dp_strlcpy(mask->info.mod, str, sizeof(mask->info.mod));
break;
case SLIF_GAME:
- dp_strlcpy( mask->info.game, str, sizeof(mask->info.game) );
+ mask->info.game_len = dp_strlcpy(mask->info.game, str, sizeof(mask->info.game));
break;
default:
VM_Warning(prog, "VM_M_setserverlistmaskstring: Bad field number %i passed!\n", field );
}
switch( (int) PRVM_G_FLOAT(OFS_PARM0) ) {
case SLIF_CNAME:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.cname );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cache->info.cname, cache->info.cname_len);
break;
case SLIF_NAME:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.name );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cache->info.name, cache->info.name_len);
break;
case SLIF_QCSTATUS:
- PRVM_G_INT (OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.qcstatus );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cache->info.qcstatus, cache->info.qcstatus_len);
break;
case SLIF_PLAYERS:
- PRVM_G_INT (OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.players );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cache->info.players, cache->info.players_len);
break;
case SLIF_GAME:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.game );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cache->info.game, cache->info.game_len);
break;
case SLIF_MOD:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.mod );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cache->info.mod, cache->info.mod_len);
break;
case SLIF_MAP:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->info.map );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cache->info.map, cache->info.map_len);
break;
// TODO remove this again
case 1024:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->line1 );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cache->line1, cache->line1_len);
break;
case 1025:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, cache->line2 );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cache->line2, cache->line2_len);
break;
default:
Con_Print("VM_M_getserverliststring: bad field number passed!\n");
VM_CheckEmptyString( prog, s );
if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, keyfp, sizeof(keyfp), NULL, 0, NULL, NULL))
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, keyfp );
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, keyfp, strlen(keyfp));
else
PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
}
VM_CheckEmptyString( prog, s );
if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, NULL, 0, idfp, sizeof(idfp), NULL, NULL))
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, idfp );
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString( prog, idfp, strlen(idfp));
else
PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
}
VM_CheckEmptyString( prog, s );
if(LHNETADDRESS_FromString(&addr, s, 26000) && Crypto_RetrieveHostKey(&addr, NULL, NULL, 0, NULL, 0, &aeslevel, NULL))
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, aeslevel ? va(vabuf, sizeof(vabuf), "%d AES128", aeslevel) : "0");
+ {
+ if (aeslevel)
+ {
+ size_t vabuf_len = dpsnprintf(vabuf, sizeof(vabuf), "%d AES128", aeslevel);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, vabuf, vabuf_len);
+ }
+ else
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "0", 1);
+ }
else
PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
}
switch(Crypto_RetrieveLocalKey(i, keyfp, sizeof(keyfp), NULL, 0, NULL))
{
case -1:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, "");
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, "", 0);
break;
case 0:
PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
break;
default:
case 1:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, keyfp);
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, keyfp, strlen(keyfp));
break;
}
}
switch(Crypto_RetrieveLocalKey(i, NULL, 0, idfp, sizeof(idfp), NULL))
{
case -1:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, "");
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, "", 0);
break;
case 0:
PRVM_G_INT( OFS_RETURN ) = OFS_NULL;
break;
default:
case 1:
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, idfp);
+ PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, idfp, strlen(idfp));
break;
}
}
entry = &serverlist_cache[n];
memset(entry, 0, sizeof(*entry));
- dp_strlcpy(entry->info.cname, addressstring, sizeof(entry->info.cname));
+ entry->info.cname_len = dp_strlcpy(entry->info.cname, addressstring, sizeof(entry->info.cname));
// use the broadcast as the first query, NetConn_QueryQueueFrame() will send more
entry->querytime = masterquerytime;
serverlist_info_t *info = &entry->info;
// update description strings for engine menu and console output
- dpsnprintf(entry->line1, sizeof(serverlist_cache[n].line1), "^%c%5.0f^7 ^%c%3u^7/%3u %-65.65s",
+ entry->line1_len = dpsnprintf(entry->line1, sizeof(serverlist_cache[n].line1), "^%c%5.0f^7 ^%c%3u^7/%3u %-65.65s",
info->ping >= 300 ? '1' : (info->ping >= 200 ? '3' : '7'),
info->ping ?: INFINITY, // display inf when a listed server times out and net_slist_pause blocks its removal
((info->numhumans > 0 && info->numhumans < info->maxplayers) ? (info->numhumans >= 4 ? '7' : '3') : '1'),
info->numplayers,
info->maxplayers,
info->name);
- dpsnprintf(entry->line2, sizeof(serverlist_cache[n].line2), "^4%-21.21s %-19.19s ^%c%-17.17s^4 %-20.20s", info->cname, info->game,
+ entry->line2_len = dpsnprintf(entry->line2, sizeof(serverlist_cache[n].line2), "^4%-21.21s %-19.19s ^%c%-17.17s^4 %-20.20s", info->cname, info->game,
(
info->gameversion != gameversion.integer
&&
entry = &serverlist_cache[n];
memset(entry, 0, sizeof(*entry));
entry->protocol = protocol;
- dp_strlcpy(entry->info.cname, ipstring, sizeof(entry->info.cname));
+ entry->info.cname_len = dp_strlcpy(entry->info.cname, ipstring, sizeof(entry->info.cname));
entry->info.isfavorite = isfavorite;
serverlist_cachecount++;
return true;
info = &serverlist_cache[n].info;
- info->game[0] = 0;
- info->mod[0] = 0;
- info->map[0] = 0;
- info->name[0] = 0;
- info->qcstatus[0] = 0;
- info->players[0] = 0;
- info->protocol = -1;
- info->numplayers = 0;
- info->numbots = -1;
+ info->game[0] = '\0'; info->game_len = 0;
+ info->mod[0] = '\0'; info->mod_len = 0;
+ info->map[0] = '\0'; info->map_len = 0;
+ info->name[0] = '\0'; info->name_len = 0;
+ info->qcstatus[0] = '\0'; info->qcstatus_len = 0;
+ info->players[0] = '\0'; info->players_len = 0;
+ info->protocol = -1;
+ info->numplayers = 0;
+ info->numbots = -1;
info->maxplayers = 0;
info->gameversion = 0;
else
Con_Printf("statusResponse without players block?\n");
- if ((s = InfoString_GetValue(string, "gamename" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->game, s, sizeof (info->game));
- if ((s = InfoString_GetValue(string, "modname" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->mod , s, sizeof (info->mod ));
- if ((s = InfoString_GetValue(string, "mapname" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->map , s, sizeof (info->map ));
- if ((s = InfoString_GetValue(string, "hostname" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->name, s, sizeof (info->name));
+ if ((s = InfoString_GetValue(string, "gamename" , infostringvalue, sizeof(infostringvalue))) != NULL) info->game_len = dp_strlcpy(info->game, s, sizeof(info->game));
+ if ((s = InfoString_GetValue(string, "modname" , infostringvalue, sizeof(infostringvalue))) != NULL) info->mod_len = dp_strlcpy(info->mod, s, sizeof(info->mod));
+ if ((s = InfoString_GetValue(string, "mapname" , infostringvalue, sizeof(infostringvalue))) != NULL) info->map_len = dp_strlcpy(info->map, s, sizeof(info->map));
+ if ((s = InfoString_GetValue(string, "hostname" , infostringvalue, sizeof(infostringvalue))) != NULL) info->name_len = dp_strlcpy(info->name, s, sizeof(info->name));
if ((s = InfoString_GetValue(string, "protocol" , infostringvalue, sizeof(infostringvalue))) != NULL) info->protocol = atoi(s);
if ((s = InfoString_GetValue(string, "clients" , infostringvalue, sizeof(infostringvalue))) != NULL) info->numplayers = atoi(s);
if ((s = InfoString_GetValue(string, "bots" , infostringvalue, sizeof(infostringvalue))) != NULL) info->numbots = atoi(s);
if ((s = InfoString_GetValue(string, "sv_maxclients", infostringvalue, sizeof(infostringvalue))) != NULL) info->maxplayers = atoi(s);
if ((s = InfoString_GetValue(string, "gameversion" , infostringvalue, sizeof(infostringvalue))) != NULL) info->gameversion = atoi(s);
- if ((s = InfoString_GetValue(string, "qcstatus" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->qcstatus, s, sizeof(info->qcstatus));
- if (p != NULL) dp_strlcpy(info->players, p, sizeof(info->players));
+ if ((s = InfoString_GetValue(string, "qcstatus" , infostringvalue, sizeof(infostringvalue))) != NULL) info->qcstatus_len = dp_strlcpy(info->qcstatus, s, sizeof(info->qcstatus));
+ if (p != NULL) info->players_len = dp_strlcpy(info->players, p, sizeof(info->players));
info->numhumans = info->numplayers - max(0, info->numbots);
info->freeslots = info->maxplayers - info->numplayers;
return true;
info = &serverlist_cache[n].info;
- info->game[0] = 0;
- info->mod[0] = 0;
- info->map[0] = 0;
- info->name[0] = 0;
- info->qcstatus[0] = 0;
- info->players[0] = 0;
- info->protocol = -1;
- info->numplayers = 0;
- info->numbots = -1;
+ info->game[0] = '\0'; info->game_len = 0;
+ info->mod[0] = '\0'; info->mod_len = 0;
+ info->map[0] = '\0'; info->map_len = 0;
+ info->name[0] = '\0'; info->name_len = 0;
+ info->qcstatus[0] = '\0'; info->qcstatus_len = 0;
+ info->players[0] = '\0'; info->players_len = 0;
+ info->protocol = -1;
+ info->numplayers = 0;
+ info->numbots = -1;
info->maxplayers = 0;
info->gameversion = 0;
- if ((s = InfoString_GetValue(string, "gamename" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->game, s, sizeof (info->game));
- if ((s = InfoString_GetValue(string, "modname" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->mod , s, sizeof (info->mod ));
- if ((s = InfoString_GetValue(string, "mapname" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->map , s, sizeof (info->map ));
- if ((s = InfoString_GetValue(string, "hostname" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->name, s, sizeof (info->name));
+ if ((s = InfoString_GetValue(string, "gamename" , infostringvalue, sizeof(infostringvalue))) != NULL) info->game_len = dp_strlcpy(info->game, s, sizeof(info->game));
+ if ((s = InfoString_GetValue(string, "modname" , infostringvalue, sizeof(infostringvalue))) != NULL) info->mod_len = dp_strlcpy(info->mod, s, sizeof(info->mod));
+ if ((s = InfoString_GetValue(string, "mapname" , infostringvalue, sizeof(infostringvalue))) != NULL) info->map_len = dp_strlcpy(info->map, s, sizeof(info->map));
+ if ((s = InfoString_GetValue(string, "hostname" , infostringvalue, sizeof(infostringvalue))) != NULL) info->name_len = dp_strlcpy(info->name, s, sizeof(info->name));
if ((s = InfoString_GetValue(string, "protocol" , infostringvalue, sizeof(infostringvalue))) != NULL) info->protocol = atoi(s);
if ((s = InfoString_GetValue(string, "clients" , infostringvalue, sizeof(infostringvalue))) != NULL) info->numplayers = atoi(s);
if ((s = InfoString_GetValue(string, "bots" , infostringvalue, sizeof(infostringvalue))) != NULL) info->numbots = atoi(s);
if ((s = InfoString_GetValue(string, "sv_maxclients", infostringvalue, sizeof(infostringvalue))) != NULL) info->maxplayers = atoi(s);
if ((s = InfoString_GetValue(string, "gameversion" , infostringvalue, sizeof(infostringvalue))) != NULL) info->gameversion = atoi(s);
- if ((s = InfoString_GetValue(string, "qcstatus" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->qcstatus, s, sizeof(info->qcstatus));
+ if ((s = InfoString_GetValue(string, "qcstatus" , infostringvalue, sizeof(infostringvalue))) != NULL) info->qcstatus_len = dp_strlcpy(info->qcstatus, s, sizeof(info->qcstatus));
info->numhumans = info->numplayers - max(0, info->numbots);
info->freeslots = info->maxplayers - info->numplayers;
info = &serverlist_cache[n].info;
dp_strlcpy(info->game, "QuakeWorld", sizeof(info->game));
- if ((s = InfoString_GetValue(string, "*gamedir" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->mod , s, sizeof (info->mod ));else info->mod[0] = 0;
- if ((s = InfoString_GetValue(string, "map" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->map , s, sizeof (info->map ));else info->map[0] = 0;
- if ((s = InfoString_GetValue(string, "hostname" , infostringvalue, sizeof(infostringvalue))) != NULL) dp_strlcpy(info->name, s, sizeof (info->name));else info->name[0] = 0;
+ if ((s = InfoString_GetValue(string, "*gamedir" , infostringvalue, sizeof(infostringvalue))) != NULL) info->mod_len = dp_strlcpy(info->mod, s, sizeof(info->mod));
+ else { info->mod[0] = '\0'; info->mod_len = 0; }
+ if ((s = InfoString_GetValue(string, "map" , infostringvalue, sizeof(infostringvalue))) != NULL) info->map_len = dp_strlcpy(info->map, s, sizeof(info->map));
+ else { info->map[0] = '\0'; info->map_len = 0; }
+ if ((s = InfoString_GetValue(string, "hostname" , infostringvalue, sizeof(infostringvalue))) != NULL) info->name_len = dp_strlcpy(info->name, s, sizeof(info->name));
+ else { info->name[0] = '\0'; info->name_len = 0; }
info->protocol = 0;
info->numplayers = 0; // updated below
info->numhumans = 0; // updated below
break;
info = &serverlist_cache[n].info;
- dp_strlcpy(info->game, "Quake", sizeof(info->game));
- dp_strlcpy(info->mod , "", sizeof(info->mod)); // mod name is not specified
- dp_strlcpy(info->name, MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)), sizeof(info->name));
- dp_strlcpy(info->map , MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)), sizeof(info->map));
+ info->game_len = dp_strlcpy(info->game, "Quake", sizeof(info->game));
+ info->mod_len = dp_strlcpy(info->mod, "", sizeof(info->mod)); // mod name is not specified
+ info->name_len = dp_strlcpy(info->name, MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)), sizeof(info->name));
+ info->map_len = dp_strlcpy(info->map, MSG_ReadString(&cl_message, cl_readstring, sizeof(cl_readstring)), sizeof(info->map));
info->numplayers = MSG_ReadByte(&cl_message);
info->maxplayers = MSG_ReadByte(&cl_message);
info->protocol = MSG_ReadByte(&cl_message);
{
/// address for connecting
char cname[128];
+ unsigned cname_len;
/// ping time for sorting servers, in milliseconds, 0 means no data
unsigned ping;
/// name of the game
char game[32];
+ unsigned game_len;
/// name of the mod
char mod[32];
+ unsigned mod_len;
/// name of the map
char map[32];
+ unsigned map_len;
/// name of the session
char name[128];
+ unsigned name_len;
/// qc-defined short status string
char qcstatus[128];
+ unsigned qcstatus_len;
/// frags/ping/name list (if they fit in the packet)
char players[2800];
+ unsigned players_len;
/// max client number
int maxplayers;
/// number of currently connected players (including bots)
// legacy stuff
char line1[128];
+ unsigned line1_len;
char line2[128];
+ unsigned line2_len;
} serverlist_entry_t;
typedef struct serverlist_mask_s
const char *PRVM_GetString(prvm_prog_t *prog, int num);
int PRVM_SetEngineString(prvm_prog_t *prog, const char *s);
const char *PRVM_ChangeEngineString(prvm_prog_t *prog, int i, const char *s);
-int PRVM_SetTempString(prvm_prog_t *prog, const char *s);
+/// Takes an strlen (not a buffer size).
+int PRVM_SetTempString(prvm_prog_t *prog, const char *s, size_t slen);
int PRVM_AllocString(prvm_prog_t *prog, size_t bufferlength, char **pointer);
void PRVM_FreeString(prvm_prog_t *prog, int num);
prog->error_cmd("%s: Bad string", prog->name);
}
-qbool PRVM_ConsoleCommand (prvm_prog_t *prog, const char *text, int *func, qbool preserve_self, int curself, double ptime, qbool prog_loaded, const char *error_message)
+qbool PRVM_ConsoleCommand(prvm_prog_t *prog, const char *text, size_t textlen, int *func, qbool preserve_self, int curself, double ptime, qbool prog_loaded, const char *error_message)
{
int restorevm_tempstringsbuf_cursize;
int save_self = 0; // hush compiler warning
PRVM_gameglobalfloat(time) = ptime;
PRVM_gameglobaledict(self) = curself;
restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
- PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, text);
+ PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, text, textlen);
prog->ExecuteProgram(prog, *func, error_message);
prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
if(preserve_self)
*/
void VM_cvar_string(prvm_prog_t *prog)
{
- char string[VM_TEMPSTRING_MAXSIZE];
+ char cvar_name[VM_TEMPSTRING_MAXSIZE];
+
VM_SAFEPARMCOUNTRANGE(1,8,VM_cvar_string);
- VM_VarString(prog, 0, string, sizeof(string));
- VM_CheckEmptyString(prog, string);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, PRVM_Cvar_ReadOk(prog, string) ? Cvar_VariableString(prog->console_cmd->cvars, string, prog->console_cmd->cvars_flagsmask) : "");
+ VM_VarString(prog, 0, cvar_name, sizeof(cvar_name));
+ VM_CheckEmptyString(prog, cvar_name);
+ if (PRVM_Cvar_ReadOk(prog, cvar_name))
+ {
+ const char *cvar_string = Cvar_VariableString(prog->console_cmd->cvars, cvar_name, prog->console_cmd->cvars_flagsmask);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cvar_string, strlen(cvar_string));
+ }
+ else
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "", 0);
}
*/
void VM_cvar_defstring(prvm_prog_t *prog)
{
- char string[VM_TEMPSTRING_MAXSIZE];
+ char cvar_name[VM_TEMPSTRING_MAXSIZE];
+ const char *cvar_defstring;
+
VM_SAFEPARMCOUNTRANGE(1,8,VM_cvar_defstring);
- VM_VarString(prog, 0, string, sizeof(string));
- VM_CheckEmptyString(prog, string);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, Cvar_VariableDefString(prog->console_cmd->cvars, string, prog->console_cmd->cvars_flagsmask));
+ VM_VarString(prog, 0, cvar_name, sizeof(cvar_name));
+ VM_CheckEmptyString(prog, cvar_name);
+ cvar_defstring = Cvar_VariableDefString(prog->console_cmd->cvars, cvar_name, prog->console_cmd->cvars_flagsmask);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cvar_defstring, strlen(cvar_defstring));
}
/*
*/
void VM_cvar_description(prvm_prog_t *prog)
{
- char string[VM_TEMPSTRING_MAXSIZE];
+ char cvar_name[VM_TEMPSTRING_MAXSIZE];
+ const char *cvar_desc;
+
VM_SAFEPARMCOUNTRANGE(1,8,VM_cvar_description);
- VM_VarString(prog, 0, string, sizeof(string));
- VM_CheckEmptyString(prog, string);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, Cvar_VariableDescription(prog->console_cmd->cvars, string, prog->console_cmd->cvars_flagsmask));
+ VM_VarString(prog, 0, cvar_name, sizeof(cvar_name));
+ VM_CheckEmptyString(prog, cvar_name);
+ cvar_desc = Cvar_VariableDescription(prog->console_cmd->cvars, cvar_name, prog->console_cmd->cvars_flagsmask);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cvar_desc, strlen(cvar_desc));
}
/*
=================
{
prvm_vec_t v;
char s[128];
+ size_t slen;
VM_SAFEPARMCOUNT(1, VM_ftos);
v = PRVM_G_FLOAT(OFS_PARM0);
if ((prvm_vec_t)((prvm_int_t)v) == v)
- dpsnprintf(s, sizeof(s), "%.0f", v);
+ slen = dpsnprintf(s, sizeof(s), "%.0f", v);
else
- dpsnprintf(s, sizeof(s), "%f", v);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, s);
+ slen = dpsnprintf(s, sizeof(s), "%f", v);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, s, slen);
}
/*
void VM_vtos(prvm_prog_t *prog)
{
char s[512];
+ size_t slen;
VM_SAFEPARMCOUNT(1,VM_vtos);
- dpsnprintf (s, sizeof(s), "'%5.1f %5.1f %5.1f'", PRVM_G_VECTOR(OFS_PARM0)[0], PRVM_G_VECTOR(OFS_PARM0)[1], PRVM_G_VECTOR(OFS_PARM0)[2]);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, s);
+ slen = dpsnprintf(s, sizeof(s), "'%5.1f %5.1f %5.1f'", PRVM_G_VECTOR(OFS_PARM0)[0], PRVM_G_VECTOR(OFS_PARM0)[1], PRVM_G_VECTOR(OFS_PARM0)[2]);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, s, slen);
}
/*
void VM_etos(prvm_prog_t *prog)
{
char s[128];
+ size_t slen;
VM_SAFEPARMCOUNT(1, VM_etos);
- dpsnprintf (s, sizeof(s), "entity %i", PRVM_G_EDICTNUM(OFS_PARM0));
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, s);
+ slen = dpsnprintf(s, sizeof(s), "entity %i", PRVM_G_EDICTNUM(OFS_PARM0));
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, s, slen);
}
/*
#endif
char fmt[VM_TEMPSTRING_MAXSIZE];
char result[VM_TEMPSTRING_MAXSIZE];
+ size_t result_len;
+
VM_SAFEPARMCOUNTRANGE(2, 8, VM_strftime);
VM_VarString(prog, 1, fmt, sizeof(fmt));
t = time(NULL);
return;
}
#if _MSC_VER >= 1400
- strftime(result, sizeof(result), fmt, &tm);
+ result_len = strftime(result, sizeof(result), fmt, &tm);
#else
- strftime(result, sizeof(result), fmt, tm);
+ result_len = strftime(result, sizeof(result), fmt, tm);
#endif
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, result);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, result, result_len);
}
/*
if (end < VM_TEMPSTRING_MAXSIZE - 1)
string[end++] = c;
}
- string[end] = 0;
+ string[end] = '\0';
// remove \n following \r
if (c == '\r')
{
if (developer_extra.integer)
Con_DPrintf("fgets: %s: %s\n", prog->name, string);
if (c >= 0 || end)
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string, end);
}
/*
if (i < 0 || i >= prog->numfielddefs)
{
VM_Warning(prog, "VM_entityfieldname: %s: field index out of bounds\n", prog->name);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "");
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "", 0);
return;
}
if (i < 0 || i >= prog->numfielddefs)
{
- VM_Warning(prog, "VM_entityfielddata: %s: field index out of bounds\n", prog->name);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "");
+ VM_Warning(prog, "VM_entityfielddata: %s: field index out of bounds\n", prog->name);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "", 0);
return;
}
ent = PRVM_G_EDICT(OFS_PARM1);
if(ent->free)
{
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "");
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "", 0);
VM_Warning(prog, "VM_entityfielddata: %s: entity %i is free !\n", prog->name, PRVM_NUM_FOR_EDICT(ent));
return;
}
break;
if (j == prvm_type_size[type])
{
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "");
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "", 0);
return;
}
-
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, PRVM_UglyValueString(prog, (etype_t)d->type, val, valuebuf, sizeof(valuebuf)));
+
+ PRVM_UglyValueString(prog, (etype_t)d->type, val, valuebuf, sizeof(valuebuf));
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, valuebuf, strlen(valuebuf));
}
// KrimZon - DP_QC_ENTITYDATA
void VM_strdecolorize(prvm_prog_t *prog)
{
char szNewString[VM_TEMPSTRING_MAXSIZE];
+ size_t szNewString_len;
const char *szString;
// Prepare Strings
VM_SAFEPARMCOUNT(1,VM_strdecolorize);
szString = PRVM_G_STRING(OFS_PARM0);
- COM_StringDecolorize(szString, 0, szNewString, sizeof(szNewString), true);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, szNewString);
+ szNewString_len = COM_StringDecolorize(szString, 0, szNewString, sizeof(szNewString), true);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, szNewString, szNewString_len);
}
// DRESK - String Length (not counting color codes)
void VM_strtolower(prvm_prog_t *prog)
{
char szNewString[VM_TEMPSTRING_MAXSIZE];
+ size_t szNewString_len;
const char *szString;
// Prepare Strings
VM_SAFEPARMCOUNT(1,VM_strtolower);
szString = PRVM_G_STRING(OFS_PARM0);
- COM_ToLowerString(szString, szNewString, sizeof(szNewString) );
+ szNewString_len = COM_ToLowerString(szString, szNewString, sizeof(szNewString) );
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, szNewString);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, szNewString, szNewString_len);
}
/*
void VM_strtoupper(prvm_prog_t *prog)
{
char szNewString[VM_TEMPSTRING_MAXSIZE];
+ size_t szNewString_len;
const char *szString;
// Prepare Strings
VM_SAFEPARMCOUNT(1,VM_strtoupper);
szString = PRVM_G_STRING(OFS_PARM0);
- COM_ToUpperString(szString, szNewString, sizeof(szNewString) );
+ szNewString_len = COM_ToUpperString(szString, szNewString, sizeof(szNewString) );
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, szNewString);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, szNewString, szNewString_len);
}
/*
void VM_strcat(prvm_prog_t *prog)
{
char s[VM_TEMPSTRING_MAXSIZE];
+ size_t slen;
+
VM_SAFEPARMCOUNTRANGE(1, 8, VM_strcat);
- VM_VarString(prog, 0, s, sizeof(s));
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, s);
+ slen = VM_VarString(prog, 0, s, sizeof(s));
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, s, slen);
}
/*
u_start = u8_byteofs(s, start, NULL);
if (u_start < 0)
{
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "");
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "", 0);
return;
}
u_length = u8_bytelen(s + u_start, length);
u_length = sizeof(string)-1;
memcpy(string, s + u_start, u_length);
- string[u_length] = 0;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string);
+ string[u_length] = '\0';
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string, u_length);
}
/*
string[si++] = subject[i];
string[si] = '\0';
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string, si);
}
/*
string[si++] = subject[i];
string[si] = '\0';
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string, si);
}
/*
if(!COM_ParseToken_VM_Tokenize(&p, false))
break;
tokens_endpos[num_tokens] = p - tokenize_string;
- tokens[num_tokens] = PRVM_SetTempString(prog, com_token);
+ tokens[num_tokens] = PRVM_SetTempString(prog, com_token, com_token_len);
++num_tokens;
}
if(!COM_ParseToken_Console(&p))
break;
tokens_endpos[num_tokens] = p - tokenize_string;
- tokens[num_tokens] = PRVM_SetTempString(prog, com_token);
+ tokens[num_tokens] = PRVM_SetTempString(prog, com_token, com_token_len);
++num_tokens;
}
tokens_endpos[num_tokens] = p0 - tokenize_string;
if (j >= (int)sizeof(tokentext))
break;
- tokentext[j++] = 0;
- tokens[num_tokens++] = PRVM_SetTempString(prog, token);
+ tokentext[j++] = '\0';
+ tokens[num_tokens++] = PRVM_SetTempString(prog, token, j - 1);
if (!*p)
break;
}
void VM_search_getfilename(prvm_prog_t *prog)
{
int handle, filenum;
+
VM_SAFEPARMCOUNT(2, VM_search_getfilename);
handle = (int)PRVM_G_FLOAT(OFS_PARM0);
return;
}
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, prog->opensearches[handle]->filenames[filenum]);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog,
+ prog->opensearches[handle]->filenames[filenum],
+ strlen(prog->opensearches[handle]->filenames[filenum]));
}
/*
char tmp[8];
int len;
- VM_SAFEPARMCOUNT(1, VM_chr);
+ VM_SAFEPARMCOUNT(1, VM_chr);
len = u8_fromchar((Uchar)PRVM_G_FLOAT(OFS_PARM0), tmp, sizeof(tmp));
- tmp[len] = 0;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, tmp);
+ tmp[len] = '\0';
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, tmp, len);
}
/*
void VM_keynumtostring (prvm_prog_t *prog)
{
char tinystr[TINYSTR_LEN];
- VM_SAFEPARMCOUNT(1, VM_keynumtostring);
+ const char *str; // Key_KeynumToString doesn't always return tinystr
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, Key_KeynumToString((int)PRVM_G_FLOAT(OFS_PARM0), tinystr, TINYSTR_LEN));
+ VM_SAFEPARMCOUNT(1, VM_keynumtostring);
+ str = Key_KeynumToString((int)PRVM_G_FLOAT(OFS_PARM0), tinystr, sizeof(tinystr));
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, str, strlen(str));
}
/*
{
const char *cmd;
char ret[VM_TEMPSTRING_MAXSIZE];
+ size_t ret_len;
int keys[FKFC_NUMKEYS];
int i;
int bindmap;
ret[0] = 0;
for(i = 0; i < FKFC_NUMKEYS; i++)
- dp_strlcat(ret, va(vabuf, sizeof(vabuf), " \'%i\'", keys[i]), sizeof(ret));
+ ret_len = dp_strlcat(ret, va(vabuf, sizeof(vabuf), " \'%i\'", keys[i]), sizeof(ret));
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, ret);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, ret, ret_len);
}
/*
void VM_getkeybind (prvm_prog_t *prog)
{
int bindmap;
+ const char *bind;
+
VM_SAFEPARMCOUNTRANGE(1, 2, VM_getkeybind);
if(prog->argc == 2)
bindmap = bound(-1, PRVM_G_FLOAT(OFS_PARM1), MAX_BINDMAPS-1);
else
bindmap = 0; // consistent to "bind"
-
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, Key_GetBind((int)PRVM_G_FLOAT(OFS_PARM0), bindmap));
+ bind = Key_GetBind((int)PRVM_G_FLOAT(OFS_PARM0), bindmap);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, bind, strlen(bind));
}
/*
else
outstr[outpos++] = *in;
}
- outstr[outpos] = 0;
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, outstr );
+ outstr[outpos] = '\0';
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, outstr, outpos);
}
/*
else
*out = *pos;
- *out = 0;
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, outstr );
+ *out = '\0';
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, outstr, out - outstr);
}
/*
if( *in == '\'' || (*in == '\\' && !*++in) )
break;
- dp_strlcpy(out, in, outstr + sizeof(outstr) - out);
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, outstr );
+ out += dp_strlcpy(out, in, outstr + sizeof(outstr) - out);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, outstr, out - outstr);
}
/*
for( ; *set ; *out++ = *set++ );
*out++ = '\'';
- dp_strlcpy(out, in, outstr + sizeof(outstr) - out);
- PRVM_G_INT( OFS_RETURN ) = PRVM_SetTempString(prog, outstr );
+ out += dp_strlcpy(out, in, outstr + sizeof(outstr) - out);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, outstr, out - outstr);
}
void VM_buf_implode (prvm_prog_t *prog)
{
prvm_stringbuffer_t *stringbuffer;
- char k[VM_TEMPSTRING_MAXSIZE];
- const char *sep;
- int i;
- size_t l;
+ char k[VM_TEMPSTRING_MAXSIZE];
+ size_t k_len;
+ const char *sep;
+ int i;
+ size_t l;
+
VM_SAFEPARMCOUNT(2, VM_buf_implode);
stringbuffer = (prvm_stringbuffer_t *)Mem_ExpandableArray_RecordAtIndex(&prog->stringbuffersarray, (int)PRVM_G_FLOAT(OFS_PARM0));
if(!stringbuffer->num_strings)
return;
sep = PRVM_G_STRING(OFS_PARM1);
- k[0] = 0;
+ k[0] = '\0';
+ k_len = 0;
for(l = i = 0;i < stringbuffer->num_strings;i++)
{
if(stringbuffer->strings[i])
if (l >= sizeof(k) - 1)
break;
dp_strlcat(k, sep, sizeof(k));
- dp_strlcat(k, stringbuffer->strings[i], sizeof(k));
+ k_len = dp_strlcat(k, stringbuffer->strings[i], sizeof(k));
}
}
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, k);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, k, k_len);
}
/*
return;
}
if (strindex < stringbuffer->num_strings && stringbuffer->strings[strindex])
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, stringbuffer->strings[strindex]);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, stringbuffer->strings[strindex], strlen(stringbuffer->strings[strindex]));
}
/*
void VM_uncolorstring (prvm_prog_t *prog)
{
char szNewString[VM_TEMPSTRING_MAXSIZE];
+ size_t szNewString_len;
const char *szString;
// Prepare Strings
VM_SAFEPARMCOUNT(1, VM_uncolorstring);
szString = PRVM_G_STRING(OFS_PARM0);
- COM_StringDecolorize(szString, 0, szNewString, sizeof(szNewString), true);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, szNewString);
-
+ szNewString_len = COM_StringDecolorize(szString, 0, szNewString, sizeof(szNewString), true);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, szNewString, szNewString_len);
}
// #221 float(string str, string sub[, float startpos]) strstrofs (FTE_STRINGS)
char t[9 * 4 + 1];
int i;
size_t len = 0;
+
VM_SAFEPARMCOUNTRANGE(0, 8, VM_chr2str);
for(i = 0; i < prog->argc && len < sizeof(t)-1; ++i)
len += u8_fromchar((Uchar)PRVM_G_FLOAT(OFS_PARM0+i*3), t + len, sizeof(t)-1);
- t[len] = 0;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, t);
+ t[len] = '\0';
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, t, len);
}
static int chrconv_number(int i, int base, int conv)
}
*result = '\0';
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, (char *) resbuf);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, (char *)resbuf, result - resbuf);
}
// #225 string(float chars, string s, ...) strpad (FTE_STRINGS)
{
char src[VM_TEMPSTRING_MAXSIZE];
char destbuf[VM_TEMPSTRING_MAXSIZE];
+ size_t destbuf_len;
int pad;
+
VM_SAFEPARMCOUNTRANGE(1, 8, VM_strpad);
pad = (int) PRVM_G_FLOAT(OFS_PARM0);
VM_VarString(prog, 1, src, sizeof(src));
// note: < 0 = left padding, > 0 = right padding,
// this is reverse logic of printf!
- dpsnprintf(destbuf, sizeof(destbuf), "%*s", -pad, src);
+ destbuf_len = dpsnprintf(destbuf, sizeof(destbuf), "%*s", -pad, src);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, destbuf);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, destbuf, destbuf_len);
}
// #226 string(string info, string key, string value, ...) infoadd (FTE_STRINGS)
InfoString_SetValue(temp, VM_TEMPSTRING_MAXSIZE, key, value);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, temp);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, temp, strlen(temp));
}
// #227 string(string info, string key) infoget (FTE_STRINGS)
InfoString_GetValue(info, key, value, VM_TEMPSTRING_MAXSIZE);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, value);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, value, strlen(value));
}
//#228 float(string s1, string s2, float len) strncmp (FTE_STRINGS)
outhex[2*i] = hexmap[(out[i] >> 4) & 15];
outhex[2*i+1] = hexmap[(out[i] >> 0) & 15];
}
- outhex[2*i] = 0;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, outhex);
+ outhex[2*i] = '\0';
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, outhex, 2*i);
}
else
PRVM_G_INT(OFS_RETURN) = 0;
PRVM_gameglobalfloat(trace_dpstartcontents) = trace->startsupercontents;
PRVM_gameglobalfloat(trace_dphitcontents) = trace->hitsupercontents;
PRVM_gameglobalfloat(trace_dphitq3surfaceflags) = trace->hitq3surfaceflags;
- PRVM_gameglobalstring(trace_dphittexturename) = trace->hittexture ? PRVM_SetTempString(prog, trace->hittexture->name) : 0;
+ PRVM_gameglobalstring(trace_dphittexturename) = trace->hittexture ? PRVM_SetTempString(prog, trace->hittexture->name, strlen(trace->hittexture->name)) : 0;
}
void VM_ClearTraceGlobals(prvm_prog_t *prog)
*q++ = hex[ *(unsigned char *)p & 0xF];
}
}
- *q++ = 0;
+ *q = '\0';
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, dest);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, dest, q - dest);
}
// #510 string(string input, ...) uri_unescape (DP_QC_URI_ESCAPE)
// otherwise:
*q++ = *p++;
}
- *q++ = 0;
+ *q = '\0';
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, dest);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, dest, q - dest);
}
// #502 string(string filename) whichpack (DP_QC_WHICHPACK)
fn = PRVM_G_STRING(OFS_PARM0);
pack = FS_WhichPack(fn);
- PRVM_G_INT(OFS_RETURN) = pack ? PRVM_SetTempString(prog, pack) : 0;
+ PRVM_G_INT(OFS_RETURN) = pack ? PRVM_SetTempString(prog, pack, strlen(pack)) : 0;
}
typedef struct
{
if(length_received >= sizeof(handle->buffer))
length_received = sizeof(handle->buffer) - 1;
- handle->buffer[length_received] = 0;
+ handle->buffer[length_received] = '\0';
PRVM_G_FLOAT(OFS_PARM0) = handle->id;
PRVM_G_FLOAT(OFS_PARM1) = status;
- PRVM_G_INT(OFS_PARM2) = PRVM_SetTempString(prog, handle->buffer);
+ PRVM_G_INT(OFS_PARM2) = PRVM_SetTempString(prog, handle->buffer, length_received);
prog->ExecuteProgram(prog, PRVM_allfunction(URI_Get_Callback), "QC function URI_Get_Callback is missing");
}
{
const char *ip;
char normalized[128];
+ size_t normalized_len;
int port;
lhnetaddress_t addr;
if(prog->argc > 1)
port = (int) PRVM_G_FLOAT(OFS_PARM1);
- if(LHNETADDRESS_FromString(&addr, ip, port) && LHNETADDRESS_ToString(&addr, normalized, sizeof(normalized), prog->argc > 1))
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, normalized);
+ if(LHNETADDRESS_FromString(&addr, ip, port) && (normalized_len = LHNETADDRESS_ToString(&addr, normalized, sizeof(normalized), prog->argc > 1)))
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, normalized, normalized_len);
else
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "");
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, "", 0);
}
//string(prvm_prog_t *prog) getextresponse = #624; // returns the next extResponse packet that was sent to this client
int first;
--cl_net_extresponse_count;
first = (cl_net_extresponse_last + NET_EXTRESPONSE_MAX - cl_net_extresponse_count) % NET_EXTRESPONSE_MAX;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cl_net_extresponse[first]);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, cl_net_extresponse[first], strlen(cl_net_extresponse[first]));
}
}
int first;
--sv_net_extresponse_count;
first = (sv_net_extresponse_last + NET_EXTRESPONSE_MAX - sv_net_extresponse_count) % NET_EXTRESPONSE_MAX;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, sv_net_extresponse[first]);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, sv_net_extresponse[first], strlen(sv_net_extresponse[first]));
}
}
break;
}
}
+
finished:
- *o = 0;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, outbuf);
+ *o = '\0';
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, outbuf, o - outbuf);
}
{
model_t *model;
msurface_t *surface;
+
VM_SAFEPARMCOUNT(2, VM_getsurfacetexture);
PRVM_G_INT(OFS_RETURN) = OFS_NULL;
if (!(model = getmodel(prog, PRVM_G_EDICT(OFS_PARM0))) || !(surface = getsurface(model, (int)PRVM_G_FLOAT(OFS_PARM1))))
return;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, surface->texture->name);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, surface->texture->name, strlen(surface->texture->name));
}
//PF_getsurfacenearpoint, // #438 float(entity e, vector p) getsurfacenearpoint = #438;
void VM_getsurfacenearpoint(prvm_prog_t *prog)
void VM_CheckEmptyString (prvm_prog_t *prog, const char *s);
/// Returns the length of the *out string excluding the \0 terminator.
size_t VM_VarString(prvm_prog_t *prog, int first, char *out, size_t outsize);
-qbool PRVM_ConsoleCommand (prvm_prog_t *prog, const char *text, int *func, qbool preserve_self, int curself, double ptime, qbool prog_loaded, const char *error_message);
+qbool PRVM_ConsoleCommand(prvm_prog_t *prog, const char *text, size_t textlen, int *func, qbool preserve_self, int curself, double ptime, qbool prog_loaded, const char *error_message);
prvm_stringbuffer_t *BufStr_FindCreateReplace (prvm_prog_t *prog, int bufindex, int flags, const char *format);
void BufStr_Set(prvm_prog_t *prog, prvm_stringbuffer_t *stringbuffer, int strindex, const char *str);
void BufStr_Del(prvm_prog_t *prog, prvm_stringbuffer_t *stringbuffer);
#include "quakedef.h"
#include "progsvm.h"
#include "csprogs.h"
+#include "prvm_cmds.h"
prvm_prog_t prvm_prog_list[PRVM_PROG_MAX];
s = Cmd_Args(cmd);
restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
- PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, s ? s : "");
+ PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, s ? s : "", s ? strlen(s) : 0);
prog->ExecuteProgram(prog, PRVM_allfunction(GameCommand), "QC function GameCommand is missing");
prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
}
// restores it on return, so multiple recursive calls can share the same
// buffer)
// the buffer size is automatically grown as needed
-
-int PRVM_SetTempString(prvm_prog_t *prog, const char *s)
+int PRVM_SetTempString(prvm_prog_t *prog, const char *s, size_t slen)
{
- int size;
+ size_t size;
char *t;
- if (!s)
+
+ if (!s || slen >= VM_TEMPSTRING_MAXSIZE)
return 0;
- size = (int)strlen(s) + 1;
+ size = slen + 1;
if (developer_insane.integer)
- Con_DPrintf("PRVM_SetTempString %s: cursize %i, size %i\n", prog->name, prog->tempstringsbuf.cursize, size);
- if (prog->tempstringsbuf.maxsize < prog->tempstringsbuf.cursize + size)
+ Con_DPrintf("PRVM_SetTempString %s: cursize %i, size %zu\n", prog->name, prog->tempstringsbuf.cursize, size);
+ if ((size_t)prog->tempstringsbuf.maxsize < prog->tempstringsbuf.cursize + size)
{
sizebuf_t old = prog->tempstringsbuf;
if (prog->tempstringsbuf.cursize + size >= 1<<28)
- prog->error_cmd("PRVM_SetTempString %s: ran out of tempstring memory! (refusing to grow tempstring buffer over 256MB, cursize %i, size %i)\n", prog->name, prog->tempstringsbuf.cursize, size);
+ prog->error_cmd("PRVM_SetTempString %s: ran out of tempstring memory! (refusing to grow tempstring buffer over 256MB, cursize %i, size %zu)\n", prog->name, prog->tempstringsbuf.cursize, size);
prog->tempstringsbuf.maxsize = max(prog->tempstringsbuf.maxsize, 65536);
- while (prog->tempstringsbuf.maxsize < prog->tempstringsbuf.cursize + size)
+ while ((size_t)prog->tempstringsbuf.maxsize < prog->tempstringsbuf.cursize + size)
prog->tempstringsbuf.maxsize *= 2;
if (prog->tempstringsbuf.maxsize != old.maxsize || prog->tempstringsbuf.data == NULL)
{
void SV_Spawn_f(cmd_state_t *cmd);
void SV_Begin_f(cmd_state_t *cmd);
-qbool SV_VM_ConsoleCommand (const char *text);
+qbool SV_VM_ConsoleCommand(const char *text, size_t textlen);
#endif
prvm_prog_t *prog = SVVM_prog;
int netcmd, num, start;
char *s, *p, *q;
+ size_t slen;
if(sv_autodemo_perclient.integer >= 2)
SV_WriteDemoMessage(host_client, &(host_client->netconnection->message), true);
// allow reliable messages now as the client is done with initial loading
if (host_client->sendsignon == 2)
host_client->sendsignon = 0;
- s = MSG_ReadString(&sv_message, sv_readstring, sizeof(sv_readstring));
+ slen = MSG_ReadString_len(&sv_message, sv_readstring, sizeof(sv_readstring));
+ s = sv_readstring;
q = NULL;
for(p = s; *p; ++p) switch(*p)
{
if (strncasecmp(s, "spawn", 5) == 0
|| strncasecmp(s, "begin", 5) == 0
|| strncasecmp(s, "prespawn", 8) == 0)
- Cmd_ExecuteString (cmd_serverfromclient, s, src_client, true);
+ Cmd_ExecuteString(cmd_serverfromclient, s, slen, src_client, true);
else if (PRVM_serverfunction(SV_ParseClientCommand))
{
int restorevm_tempstringsbuf_cursize;
restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
- PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, s);
+ PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, s, slen);
PRVM_serverglobalfloat(time) = sv.time;
PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(host_client->edict);
prog->ExecuteProgram(prog, PRVM_serverfunction(SV_ParseClientCommand), "QC function SV_ParseClientCommand is missing");
prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
}
else
- Cmd_ExecuteString (cmd_serverfromclient, s, src_client, true);
+ Cmd_ExecuteString(cmd_serverfromclient, s, slen, src_client, true);
break;
clc_stringcmd_invalid:
temp_client = host_client;
host_client = svs.clients + i;
- Cmd_ExecuteString(cmd_serverfromclient, PRVM_G_STRING(OFS_PARM1), src_client, true);
+ Cmd_ExecuteString(cmd_serverfromclient, PRVM_G_STRING(OFS_PARM1), strlen(PRVM_G_STRING(OFS_PARM1)), src_client, true);
host_client = temp_client;
}
Matrix4x4_ToVectors(&tag_localmatrix, forward, left, up, origin);
PRVM_serverglobalfloat(gettaginfo_parent) = parentindex;
- PRVM_serverglobalstring(gettaginfo_name) = tagname ? PRVM_SetTempString(prog, tagname) : 0;
+ PRVM_serverglobalstring(gettaginfo_name) = tagname ? PRVM_SetTempString(prog, tagname, strlen(tagname)) : 0;
VectorCopy(forward, PRVM_serverglobalvector(gettaginfo_forward));
VectorNegate(left, PRVM_serverglobalvector(gettaginfo_right));
VectorCopy(up, PRVM_serverglobalvector(gettaginfo_up));
static void VM_SV_serverkey(prvm_prog_t *prog)
{
char string[VM_TEMPSTRING_MAXSIZE];
+
VM_SAFEPARMCOUNT(1, VM_SV_serverkey);
InfoString_GetValue(svs.serverinfo, PRVM_G_STRING(OFS_PARM0), string, sizeof(string));
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, string, strlen(string));
}
//#333 void(entity e, float mdlindex) setmodelindex (EXT_CSQC)
SV_FlushBroadcastMessages();
}
-qbool SV_VM_ConsoleCommand (const char *text)
+qbool SV_VM_ConsoleCommand(const char *text, size_t textlen)
{
prvm_prog_t *prog = SVVM_prog;
- return PRVM_ConsoleCommand(prog, text, &prog->funcoffsets.ConsoleCmd, true, PRVM_EDICT_TO_PROG(sv.world.prog->edicts), sv.time, !(!sv.active || !prog || !prog->loaded), "QC function ConsoleCmd is missing");
+ return PRVM_ConsoleCommand(prog, text, textlen, &prog->funcoffsets.ConsoleCmd, true, PRVM_EDICT_TO_PROG(sv.world.prog->edicts), sv.time, !(!sv.active || !prog || !prog->loaded), "QC function ConsoleCmd is missing");
}
// #352 void(string cmdname) registercommand (EXT_CSQC)
return;
if (bonenum < 0 || bonenum >= skeleton->model->num_bones)
return;
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, skeleton->model->data_bones[bonenum].name);
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, skeleton->model->data_bones[bonenum].name, strlen(skeleton->model->data_bones[bonenum].name));
}
// #267 float(float skel, float bonenum) skel_get_boneparent = #267; // (FTE_CSQC_SKELETONOBJECTS) returns parent num for supplied bonenum, 0 if bonenum has no parent or bone does not exist (returned value is always less than bonenum, you can loop on this)