From 49efc53510842f29eccbc160e1aa56c17e575468 Mon Sep 17 00:00:00 2001 From: molivier Date: Fri, 2 Apr 2004 07:12:10 +0000 Subject: [PATCH] strncpy -> {strlcpy,memcpy}. Replaced the "forceloop" boolean in "channel_t" by a flags field. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4076 d7cf8633-e32d-0410-b094-e92efae38249 --- model_brush.c | 2 +- netconn.c | 4 ++-- pr_edict.c | 10 +++++----- prvm_edict.c | 10 +++++----- snd_dma.c | 10 ++++++---- snd_mix.c | 4 ++-- sound.h | 33 +++++++++++++++++++-------------- sys_shared.c | 2 +- 8 files changed, 41 insertions(+), 34 deletions(-) diff --git a/model_brush.c b/model_brush.c index 40c3dc94..0834ce95 100644 --- a/model_brush.c +++ b/model_brush.c @@ -3597,7 +3597,7 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l) text = f; while (COM_ParseToken(&text, false)) { - strncpy(shadername, com_token, sizeof(shadername)); + strlcpy (shadername, com_token, sizeof (shadername)); flags = 0; sky[0] = 0; if (COM_ParseToken(&text, false) && !strcasecmp(com_token, "{")) diff --git a/netconn.c b/netconn.c index 721b9a02..3226f763 100755 --- a/netconn.c +++ b/netconn.c @@ -800,8 +800,8 @@ int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, qbyte *data, int length, hostcache[n].ping = 100000; hostcache[n].querytime = realtime; // build description strings for the things users care about - strncpy(hostcache[n].line1, "?", sizeof(hostcache[n].line1)); - strncpy(hostcache[n].line2, ipstring, sizeof(hostcache[n].line2)); + strlcpy (hostcache[n].line1, "?", sizeof (hostcache[n].line1)); + strlcpy (hostcache[n].line2, ipstring, sizeof (hostcache[n].line2)); // if not in the slist menu we should print the server to console if (m_state != m_slist) Con_Printf("querying %s\n", ipstring); diff --git a/pr_edict.c b/pr_edict.c index 2f512093..1cb4bf9c 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -401,7 +401,7 @@ char *PR_ValueString (etype_t type, eval_t *val) switch (type) { case ev_string: - strncpy(line, PR_GetString(val->string), sizeof(line)); + strlcpy (line, PR_GetString (val->string), sizeof (line)); break; case ev_entity: //n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)); @@ -489,7 +489,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val) break; case ev_function: f = pr_functions + val->function; - strncpy(line, PR_GetString(f->s_name), sizeof(line)); + strlcpy (line, PR_GetString (f->s_name), sizeof (line)); break; case ev_field: def = ED_FieldAtOfs ( val->_int ); @@ -614,7 +614,7 @@ void ED_Print(edict_t *ed) if (strlen(name) > 256) { - strncpy(tempstring2, name, 256); + memcpy (tempstring2, name, 256); tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; tempstring2[259] = 0; name = tempstring2; @@ -627,7 +627,7 @@ void ED_Print(edict_t *ed) name = PR_ValueString(d->type, (eval_t *)v); if (strlen(name) > 256) { - strncpy(tempstring2, name, 256); + memcpy(tempstring2, name, 256); tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; tempstring2[259] = 0; name = tempstring2; @@ -1537,7 +1537,7 @@ void PR_Fields_f (void) } if (strlen(name) > 256) { - strncpy(tempstring2, name, 256); + memcpy(tempstring2, name, 256); tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; tempstring2[259] = 0; name = tempstring2; diff --git a/prvm_edict.c b/prvm_edict.c index 4cc58724..67bc940d 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -383,7 +383,7 @@ char *PRVM_ValueString (etype_t type, prvm_eval_t *val) switch (type) { case ev_string: - strncpy(line, PRVM_GetString(val->string), sizeof(line)); + strlcpy (line, PRVM_GetString (val->string), sizeof (line)); break; case ev_entity: n = val->edict; @@ -470,7 +470,7 @@ char *PRVM_UglyValueString (etype_t type, prvm_eval_t *val) break; case ev_function: f = pr_functions + val->function; - strncpy(line, PRVM_GetString(f->s_name), sizeof(line)); + strlcpy (line, PRVM_GetString (f->s_name), sizeof (line)); break; case ev_field: def = PRVM_ED_FieldAtOfs ( val->_int ); @@ -595,7 +595,7 @@ void PRVM_ED_Print(prvm_edict_t *ed) if (strlen(name) > 256) { - strncpy(tempstring2, name, 256); + memcpy (tempstring2, name, 256); tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; tempstring2[259] = 0; name = tempstring2; @@ -608,7 +608,7 @@ void PRVM_ED_Print(prvm_edict_t *ed) name = PRVM_ValueString(d->type, (prvm_eval_t *)v); if (strlen(name) > 256) { - strncpy(tempstring2, name, 256); + memcpy (tempstring2, name, 256); tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; tempstring2[259] = 0; name = tempstring2; @@ -1597,7 +1597,7 @@ void PRVM_Fields_f (void) } if (strlen(name) > 256) { - strncpy(tempstring2, name, 256); + memcpy (tempstring2, name, 256); tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; tempstring2[259] = 0; name = tempstring2; diff --git a/snd_dma.c b/snd_dma.c index 6dbc1ea2..24525fee 100644 --- a/snd_dma.c +++ b/snd_dma.c @@ -331,7 +331,7 @@ sfx_t *S_FindName (char *name) sfx = &known_sfx[num_sfx++]; memset(sfx, 0, sizeof(*sfx)); - strncpy(sfx->name, name, sizeof(sfx->name)); + strlcpy (sfx->name, name, sizeof (sfx->name)); return sfx; } @@ -448,7 +448,8 @@ channel_t *SND_PickChannel(int entnum, int entchannel) continue; // don't override looped sounds - if (ch->forceloop || (ch->sfx != NULL && ch->sfx->loopstart >= 0)) + if ((ch->flags & CHANNELFLAG_FORCELOOP) != 0 || + (ch->sfx != NULL && ch->sfx->loopstart >= 0)) continue; if (ch->end - paintedtime < life_left) @@ -564,6 +565,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f } target_chan->sfx = sfx; + target_chan->flags = CHANNELFLAG_NONE; target_chan->pos = 0.0; target_chan->end = paintedtime + sfx->total_length; target_chan->lastptime = paintedtime; @@ -708,7 +710,7 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation) ss = &channels[total_channels++]; memset(ss, 0, sizeof(*ss)); - ss->forceloop = true; + ss->flags = CHANNELFLAG_FORCELOOP; ss->sfx = sfx; VectorCopy (origin, ss->origin); ss->master_vol = vol; @@ -750,7 +752,7 @@ void S_UpdateAmbientSounds (void) (ambient_sfx[ambient_channel]->flags & SFXFLAG_SILENTLYMISSING)) continue; chan = &channels[ambient_channel]; - chan->forceloop = true; + chan->flags |= CHANNELFLAG_FORCELOOP; chan->sfx = ambient_sfx[ambient_channel]; vol = ambient_level.value * ambientlevels[ambient_channel]; diff --git a/snd_mix.c b/snd_mix.c index 6434dbcf..f6cd8e88 100644 --- a/snd_mix.c +++ b/snd_mix.c @@ -306,7 +306,7 @@ void S_PaintChannels(int endtime) { int loopstart; - if (ch->forceloop) + if (ch->flags & CHANNELFLAG_FORCELOOP) loopstart = 0; else loopstart = -1; @@ -352,7 +352,7 @@ void S_PaintChannels(int endtime) if (ltime >= ch->end) { // if at end of loop, restart - if ((sfx->loopstart >= 0 || ch->forceloop) && !stop_paint) + if ((sfx->loopstart >= 0 || (ch->flags & CHANNELFLAG_FORCELOOP)) && !stop_paint) { ch->pos = bound(0, sfx->loopstart, (int)sfx->total_length - 1); ch->end = ltime + sfx->total_length - ch->pos; diff --git a/sound.h b/sound.h index bf8b5191..8aff39c8 100644 --- a/sound.h +++ b/sound.h @@ -40,6 +40,7 @@ typedef struct } snd_format_t; // sfx_t flags +#define SFXFLAG_NONE 0 #define SFXFLAG_SILENTLYMISSING (1 << 0) // if the sfx is missing and loaded with complain = false #define SFXFLAG_USED (1 << 1) @@ -65,22 +66,26 @@ typedef struct int bufferlength; // used only by certain drivers } dma_t; +// channel_t flags +#define CHANNELFLAG_NONE 0 +#define CHANNELFLAG_FORCELOOP (1 << 0) // force looping even if the sound is not looped + typedef struct { - sfx_t *sfx; // sfx number - int forceloop; // force looping even if the sound is not looped - int leftvol; // 0-255 volume - int rightvol; // 0-255 volume - int end; // end time in global paintsamples - int lastptime; // last time this channel was painted - int pos; // sample position in sfx - int looping; // where to loop, -1 = no looping - int entnum; // to allow overriding a specific sound - int entchannel; - vec3_t origin; // origin of sound effect - vec_t dist_mult; // distance multiplier (attenuation/clipK) - int master_vol; // 0-255 master volume - void *fetcher_data; // Per-channel data for the sound fetching function + sfx_t *sfx; // sfx number + unsigned int flags; // cf CHANNELFLAG_* defines + int leftvol; // 0-255 volume + int rightvol; // 0-255 volume + int end; // end time in global paintsamples + int lastptime; // last time this channel was painted + int pos; // sample position in sfx + int looping; // where to loop, -1 = no looping + int entnum; // to allow overriding a specific sound + int entchannel; + vec3_t origin; // origin of sound effect + vec_t dist_mult; // distance multiplier (attenuation/clipK) + int master_vol; // 0-255 master volume + void *fetcher_data; // Per-channel data for the sound fetching function } channel_t; typedef const sfxbuffer_t* (*snd_fetcher_getsb_t) (channel_t* ch, unsigned int start, unsigned int nbsamples); diff --git a/sys_shared.c b/sys_shared.c index 258e6cf4..a72125f2 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -72,7 +72,7 @@ void Sys_Print(const char *msg) if (timestamps.integer) snprintf(final, sizeof(final), "%s%s", Sys_TimeString(timeformat.string), msg); else - strncpy(final, msg, sizeof(final)); + strlcpy (final, msg, sizeof (final)); // LordHavoc: make sure the string is terminated final[MAXPRINTMSG-1] = 0; -- 2.39.2