diff --git a/src/g_spawn.c b/src/g_spawn.c index a59fb48..a16e2ab 100644 --- a/src/g_spawn.c +++ b/src/g_spawn.c @@ -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]) diff --git a/src/g_target.c b/src/g_target.c index 93e1936..9108646 100644 --- a/src/g_target.c +++ b/src/g_target.c @@ -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); diff --git a/src/header/shared.h b/src/header/shared.h index 9eb68a1..fffb9ba 100644 --- a/src/header/shared.h +++ b/src/header/shared.h @@ -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); /* ============================================= */ diff --git a/src/shared/shared.c b/src/shared/shared.c index 4e05a2e..1b8635d 100644 --- a/src/shared/shared.c +++ b/src/shared/shared.c @@ -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); +} + /* * ===================================================================== *