diff --git a/src/g_spawn.c b/src/g_spawn.c index 1189333..6f9f4ac 100644 --- a/src/g_spawn.c +++ b/src/g_spawn.c @@ -874,10 +874,10 @@ void 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]) gi.configstring (CS_SKY, st.sky); diff --git a/src/g_target.c b/src/g_target.c index 33d368c..43c9943 100644 --- a/src/g_target.c +++ b/src/g_target.c @@ -76,41 +76,56 @@ void Use_Target_Speaker (edict_t *ent, edict_t *other, edict_t *activator) void SP_target_speaker (edict_t *ent) { - char buffer[MAX_QPATH]; + char buffer[MAX_QPATH]; - if (!ent) + if (!ent) { return; } - if(!st.noise) + if (!st.noise) { - gi.dprintf("target_speaker with no noise set at %s\n", vtos(ent->s.origin)); + gi.dprintf("target_speaker with no noise set at %s\n", + vtos(ent->s.origin)); return; } - if (!strstr (st.noise, ".wav")) - Com_sprintf (buffer, sizeof(buffer), "%s.wav", st.noise); + + if (!strstr(st.noise, ".wav")) + { + Com_sprintf(buffer, sizeof(buffer), "%s.wav", st.noise); + } else - strncpy (buffer, st.noise, sizeof(buffer)); - ent->noise_index = gi.soundindex (buffer); + { + Q_strlcpy(buffer, st.noise, sizeof(buffer)); + } + + ent->noise_index = gi.soundindex(buffer); if (!ent->volume) + { ent->volume = 1.0; + } if (!ent->attenuation) + { ent->attenuation = 1.0; - else if (ent->attenuation == -1) // use -1 so 0 defaults to 1 + } + else if (ent->attenuation == -1) /* use -1 so 0 defaults to 1 */ + { ent->attenuation = 0; + } - // check for prestarted looping sound + /* check for prestarted looping sound */ if (ent->spawnflags & 1) + { ent->s.sound = ent->noise_index; + } ent->use = Use_Target_Speaker; - // must link the entity so we get areas and clusters so - // the server can determine who to send updates to - gi.linkentity (ent); + /* must link the entity so we get areas and clusters so + the server can determine who to send updates to */ + gi.linkentity(ent); } diff --git a/src/header/shared.h b/src/header/shared.h index b714387..df5e46e 100644 --- a/src/header/shared.h +++ b/src/header/shared.h @@ -184,6 +184,9 @@ 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); +/* portable safe string copy/concatenate */ +int Q_strlcpy(char *dst, const char *src, int size); +int Q_strlcat(char *dst, const char *src, int size); /* ============================================= */ diff --git a/src/savegame/savegame.c b/src/savegame/savegame.c index 118d4c5..93eb5c2 100644 --- a/src/savegame/savegame.c +++ b/src/savegame/savegame.c @@ -767,10 +767,10 @@ WriteGame(const char *filename, qboolean autosave) /* Savegame identification */ memset(&sv, 0, sizeof(sv)); - strncpy(sv.ver, SAVEGAMEVER, sizeof(sv.ver)); - strncpy(sv.game, GAMEVERSION, sizeof(sv.game)); - strncpy(sv.os, YQ2OSTYPE, sizeof(sv.os) - 1); - strncpy(sv.arch, YQ2ARCH, sizeof(sv.arch)); + Q_strlcpy(sv.ver, SAVEGAMEVER, sizeof(sv.ver)); + Q_strlcpy(sv.game, GAMEVERSION, sizeof(sv.game)); + Q_strlcpy(sv.os, YQ2OSTYPE, sizeof(sv.os) - 1); + Q_strlcpy(sv.arch, YQ2ARCH, sizeof(sv.arch)); fwrite(&sv, sizeof(sv), 1, f); diff --git a/src/shared/shared.c b/src/shared/shared.c index 6a77cbc..86760f0 100644 --- a/src/shared/shared.c +++ b/src/shared/shared.c @@ -1109,6 +1109,42 @@ Com_sprintf(char *dest, int size, char *fmt, ...) strcpy(dest, bigbuffer); } +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); +} + /* * ===================================================================== *