mirror of
https://github.com/yquake2/rogue.git
synced 2024-11-10 06:42:21 +00:00
Import Q_strlcpy() and replace several dangerous strncpy() with it.
This commit is contained in:
parent
949e9aa008
commit
433a1423d9
4 changed files with 41 additions and 3 deletions
|
@ -1101,11 +1101,11 @@ SP_worldspawn(edict_t *ent)
|
|||
if (ent->message && ent->message[0])
|
||||
{
|
||||
gi.configstring(CS_NAME, ent->message);
|
||||
strncpy(level.level_name, ent->message, sizeof(level.level_name));
|
||||
Q_strlcpy(level.level_name, ent->message, sizeof(level.level_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(level.level_name, level.mapname, sizeof(level.level_name));
|
||||
Q_strlcpy(level.level_name, level.mapname, sizeof(level.level_name));
|
||||
}
|
||||
|
||||
if (st.sky && st.sky[0])
|
||||
|
|
|
@ -119,7 +119,7 @@ SP_target_speaker(edict_t *ent)
|
|||
}
|
||||
else
|
||||
{
|
||||
strncpy(buffer, st.noise, sizeof(buffer));
|
||||
Q_strlcpy(buffer, st.noise, sizeof(buffer));
|
||||
}
|
||||
|
||||
ent->noise_index = gi.soundindex(buffer);
|
||||
|
|
|
@ -184,6 +184,8 @@ void Com_sprintf(char *dest, int size, char *fmt, ...);
|
|||
void Com_PageInMemory(byte *buffer, int size);
|
||||
|
||||
char *strlwr ( char *s );
|
||||
int Q_strlcpy(char *dst, const char *src, int size);
|
||||
int Q_strlcat(char *dst, const char *src, int size);
|
||||
|
||||
/* ============================================= */
|
||||
|
||||
|
|
|
@ -1098,6 +1098,42 @@ strlwr ( char *s )
|
|||
return ( p );
|
||||
}
|
||||
|
||||
int
|
||||
Q_strlcpy(char *dst, const char *src, int size)
|
||||
{
|
||||
const char *s = src;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (size > 1)
|
||||
{
|
||||
*dst++ = *s;
|
||||
size--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (size > 0)
|
||||
{
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
return s - src;
|
||||
}
|
||||
|
||||
int
|
||||
Q_strlcat(char *dst, const char *src, int size)
|
||||
{
|
||||
char *d = dst;
|
||||
|
||||
while (size > 0 && *d)
|
||||
{
|
||||
size--;
|
||||
d++;
|
||||
}
|
||||
|
||||
return (d - dst) + Q_strlcpy(d, src, size);
|
||||
}
|
||||
|
||||
/*
|
||||
* =====================================================================
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue