]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
strncpy -> {strlcpy,memcpy}. Replaced the "forceloop" boolean in "channel_t" by a...
authormolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 2 Apr 2004 07:12:10 +0000 (07:12 +0000)
committermolivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 2 Apr 2004 07:12:10 +0000 (07:12 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4076 d7cf8633-e32d-0410-b094-e92efae38249

model_brush.c
netconn.c
pr_edict.c
prvm_edict.c
snd_dma.c
snd_mix.c
sound.h
sys_shared.c

index 40c3dc94f9acea845eff5bf5da3900ddd866fcfb..0834ce959413943f6f8a8ff9c21315eb04bd9c67 100644 (file)
@@ -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, "{"))
index 721b9a0299b594806837bda83e807786af8d139a..3226f763b34c529ae022a43aa35a641d44ea6773 100755 (executable)
--- 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);
index 2f512093eff786f34dd3361aa4383d9999e0747c..1cb4bf9cd1564f5547245b4c14599196c33d99d4 100644 (file)
@@ -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;
index 4cc5872462fa426560f1dc3d9eb9a50e0acfe070..67bc940d36d1938ef66297b4484e02320044103a 100644 (file)
@@ -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;
index 6dbc1ea299b202619dcba20192876bbf96b03cc8..24525fee956237fd4e42020ca014fe6a4f33c2ba 100644 (file)
--- 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];
index 6434dbcf2098232dda8b67db1ff4ae181f122547..f6cd8e889aec496fe909e440e0479da639978379 100644 (file)
--- 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 bf8b5191566883de40dd6c289a5cb2feaf991918..8aff39c8f29164d8ba81a7a26d618e69d26c3bb2 100644 (file)
--- 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);
index 258e6cf45c1aacffc99ce8f8392318f3e08f5af6..a72125f244940f5046f2111e45624a3d64756c7f 100644 (file)
@@ -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;