From a8d25d8be54fbd3f1a5e63ec8933d3d4d3f2d3d9 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Mon, 18 May 2020 03:10:15 +0000 Subject: [PATCH] Fix a few bugs detected by Cppcheck (warning) Logical conjunction always evaluates to false: matchrule < 0 && matchrule > 5. (style) Condition 'k<16' is always true (style) Variable 'settings->bounceminimumintensity2' is reassigned a value before the old one has been used. From terencehill git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12532 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_particles.c | 2 +- prvm_cmds.c | 8 ++++---- r_shadow.c | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cl_particles.c b/cl_particles.c index a93be5e7..2093bcb5 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -1826,7 +1826,7 @@ void CL_ParticleExplosion (const vec3_t org) VectorMA(org, 128, v2, v); trace = CL_TraceLine(org, v, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, 0, 0, collision_extendmovelength.value, true, false, NULL, false, false); } - while (k < 16 && trace.fraction < 0.1f); + while (k++ < 16 && trace.fraction < 0.1f); VectorSubtract(trace.endpos, org, v2); VectorScale(v2, 2.0f, v2); CL_NewParticle(org, pt_spark, 0x903010, 0xFFD030, tex_particle, 1.0f, 0, lhrandom(0, 255), 512, 0, 0, org[0], org[1], org[2], v2[0], v2[1], v2[2], 0, 0, 0, 0, true, 0, 1, PBLEND_ADD, PARTICLE_SPARK, -1, -1, -1, 1, 1, 0, 0, NULL); diff --git a/prvm_cmds.c b/prvm_cmds.c index 90ef213e..e2bba643 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -5386,7 +5386,7 @@ void VM_bufstr_find(prvm_prog_t *prog) char string[VM_STRINGTEMP_LENGTH]; int matchrule, matchlen, i, step; const char *match; - + VM_SAFEPARMCOUNTRANGE(3, 5, VM_bufstr_find); PRVM_G_FLOAT(OFS_RETURN) = -1; @@ -5401,7 +5401,7 @@ void VM_bufstr_find(prvm_prog_t *prog) // get pattern/rule matchrule = (int)PRVM_G_FLOAT(OFS_PARM2); - if (matchrule < 0 && matchrule > 5) + if (matchrule < 0 || matchrule > 5) { VM_Warning(prog, "VM_bufstr_find: invalid match rule %i in %s\n", matchrule, prog->name); return; @@ -5447,9 +5447,9 @@ void VM_matchpattern(prvm_prog_t *prog) // get pattern/rule matchrule = (int)PRVM_G_FLOAT(OFS_PARM2); - if (matchrule < 0 && matchrule > 5) + if (matchrule < 0 || matchrule > 5) { - VM_Warning(prog, "VM_bufstr_find: invalid match rule %i in %s\n", matchrule, prog->name); + VM_Warning(prog, "VM_matchpattern: invalid match rule %i in %s\n", matchrule, prog->name); return; } if (matchrule) diff --git a/r_shadow.c b/r_shadow.c index 3d14ab03..e6fda0f5 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -1724,7 +1724,6 @@ static void R_Shadow_BounceGrid_GenerateSettings(r_shadow_bouncegrid_settings_t settings->rng_type = r_shadow_bouncegrid_rng_type.integer; settings->rng_seed = r_shadow_bouncegrid_rng_seed.integer; settings->bounceminimumintensity2 = bounceminimumintensity * bounceminimumintensity; - settings->bounceminimumintensity2 = bounceminimumintensity * bounceminimumintensity; settings->normalizevectors = r_shadow_bouncegrid_normalizevectors.integer != 0; settings->subsamples = bound(1, r_shadow_bouncegrid_subsamples.integer, 4); -- 2.39.2