diff --git a/src/g_spawn.c b/src/g_spawn.c index cc69784..7529126 100644 --- a/src/g_spawn.c +++ b/src/g_spawn.c @@ -813,11 +813,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]) diff --git a/src/g_target.c b/src/g_target.c index 2dddf06..cd684d2 100644 --- a/src/g_target.c +++ b/src/g_target.c @@ -121,7 +121,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); diff --git a/src/header/shared.h b/src/header/shared.h index f7d3348..66e0bda 100644 --- a/src/header/shared.h +++ b/src/header/shared.h @@ -202,6 +202,8 @@ void Com_PageInMemory(byte *buffer, int size); int Q_stricmp(const char *s1, const char *s2); int Q_strcasecmp(char *s1, char *s2); int Q_strncasecmp(char *s1, char *s2, int n); +int Q_strlcpy(char *dst, const char *src, int size); +int Q_strlcat(char *dst, const char *src, int size); /* ============================================= */ diff --git a/src/shared/shared.c b/src/shared/shared.c index e183154..283ccf5 100644 --- a/src/shared/shared.c +++ b/src/shared/shared.c @@ -1072,6 +1072,43 @@ Q_strcasecmp(char *s1, char *s2) return Q_strncasecmp(s1, s2, 99999); } +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); +} + + void Com_sprintf(char *dest, int size, char *fmt, ...) {