From 84c8da2f81318413422d075f6d6d80ff84cfda97 Mon Sep 17 00:00:00 2001
From: XScreenSaver owners <xscreensaver-owner@fedoraproject.org>
Date: Sun, 15 Nov 2020 21:54:03 +0900
Subject: [PATCH] Clean up some warnings from cppcheck:
hacks/analogtv.c:650:11: warning: Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]
hacks/asm6502.c:2119:3: warning: Assignment of function parameter has no effect outside the function. Did you forget dereferencing it? [uselessAssignmentPtrArg]
hacks/bsod.c:4599:15: warning: Opposite inner 'if' condition leads to a dead code block. [oppositeInnerCondition]
hacks/bsod.c:3073:27: style: Modulo of one is always equal to zero [moduloofone]
hacks/delaunay.c:208:16: error: Common realloc mistake: 'edges' nulled but not freed upon failure [memleakOnRealloc]
hacks/glx/esper.c:642:15: warning: Either the condition '!sp' is redundant or there is possible null pointer dereference: sp. [nullPointerRedundantCheck]
hacks/glx/sonar-icmp.c:1734:7: warning: Either the condition 'if(pd)' is redundant or there is possible null pointer dereference: pd. [nullPointerRedundantCheck]
hacks/penrose.c:497:9: style: Condition 'fp==0' is always false [knownConditionTrueFalse] hacks/penrose.c:493:58: note: Assuming that condition '(fp=tp->fringe.nodes=(struct fringe_node*)malloc(sizeof(struct fringe_node)))==((void*)0)' is not redundant
hacks/tessellimage.c:368:14: warning: Either the condition 'p>sizeof(histo)' is redundant or the array 'histo[256]' is accessed at index 2048, which is out of bounds. [arrayIndexOutOfBoundsCond]
---
hacks/analogtv.c | 5 -----
hacks/asm6502.c | 1 -
hacks/bsod.c | 1 -
hacks/delaunay.c | 2 ++
hacks/glx/esper.c | 3 ++-
hacks/glx/sonar-icmp.c | 2 +-
hacks/penrose.c | 11 -----------
hacks/tessellimage.c | 2 +-
8 files changed, 6 insertions(+), 21 deletions(-)
diff --git a/hacks/analogtv.c b/hacks/analogtv.c
index 8ef3c7d..9494655 100644
--- a/hacks/analogtv.c
+++ b/hacks/analogtv.c
@@ -647,11 +647,6 @@ analogtv_set_demod(analogtv *it)
cmap_again:
if (it->use_cmap && !it->n_colors) {
- if (it->n_colors) {
- XFreeColors(it->dpy, it->colormap, it->colors, it->n_colors, 0L);
- it->n_colors=0;
- }
-
{
int yli,qli,ili;
for (yli=0; yli<y_levels; yli++) {
diff --git a/hacks/asm6502.c b/hacks/asm6502.c
index 60327a9..25a08af 100644
--- a/hacks/asm6502.c
+++ b/hacks/asm6502.c
@@ -2116,7 +2116,6 @@ machine_6502 *m6502_build(void){
void m6502_destroy6502(machine_6502 *machine){
free(machine);
- machine = NULL;
}
void m6502_trace(machine_6502 *machine, FILE *output){
diff --git a/hacks/bsod.c b/hacks/bsod.c
index ffde1a6..7f60f09 100644
--- a/hacks/bsod.c
+++ b/hacks/bsod.c
@@ -4596,7 +4596,6 @@ hpux (Display *dpy, Window window)
int size = 40;
for (i = 0; i <= steps; i++)
{
- if (i > steps) i = steps;
sprintf (buf,
"*** Dumping: %3d%% complete (%d of 40 MB) (device 64:0x2)\r",
i * 100 / steps,
diff --git a/hacks/delaunay.c b/hacks/delaunay.c
index a5ea9ae..a6db5b1 100644
--- a/hacks/delaunay.c
+++ b/hacks/delaunay.c
@@ -204,8 +204,10 @@ delaunay (int nv,XYZ *pxyz,ITRIANGLE *v,int *ntri)
if (inside) {
/* Check that we haven't exceeded the edge list size */
if (nedge+3 >= emax) {
+ IEDGE *edges_old = edges;
emax += 100;
if ((edges = realloc(edges,emax*(long)sizeof(IEDGE))) == NULL) {
+ edges = edges_old;
status = 3;
goto skip;
}
diff --git a/hacks/glx/esper.c b/hacks/glx/esper.c
index 90887a8..3852ca4 100644
--- a/hacks/glx/esper.c
+++ b/hacks/glx/esper.c
@@ -639,8 +639,9 @@ copy_sprite (ModeInfo *mi, sprite *old)
{
sprite *sp = new_sprite (mi, (sprite_type) ~0L);
int id;
- double tt = sp->start_time;
+ double tt;
if (!sp) abort();
+ tt = sp->start_time;
id = sp->id;
memcpy (sp, old, sizeof(*sp));
sp->id = id;
diff --git a/hacks/glx/sonar-icmp.c b/hacks/glx/sonar-icmp.c
index 281cc1e..26f82ac 100644
--- a/hacks/glx/sonar-icmp.c
+++ b/hacks/glx/sonar-icmp.c
@@ -1736,7 +1736,7 @@ sonar_init_ping (Display *dpy, char **error_ret, char **desc_ret,
if (! *error_ret)
*error_ret = strdup ("No hosts to ping!\n"
"Simulating instead.");
- if (pd) ping_free_data (ssd, pd);
+ ping_free_data (ssd, pd);
if (ssd) free (ssd);
return 0;
}
diff --git a/hacks/penrose.c b/hacks/penrose.c
index 6317cb6..00bae0c 100644
--- a/hacks/penrose.c
+++ b/hacks/penrose.c
@@ -494,17 +494,6 @@ init_penrose(ModeInfo * mi)
free_penrose(mi);
return;
}
- if (fp == 0) {
- if (MI_IS_VERBOSE(mi)) {
- (void) fprintf(stderr, "Weirdness in init_penrose()\n");
- (void) fprintf(stderr, "fp = 0\n");
- }
- if ((fp = tp->fringe.nodes = ALLOC_NODE(fringe_node_c)) == NULL) {
- free_penrose(mi);
- return;
- }
- tp->done = True;
- }
/* First vertex. */
fp->rule_mask = (1 << N_VERTEX_RULES) - 1;
fp->list_ptr = 0;
diff --git a/hacks/tessellimage.c b/hacks/tessellimage.c
index 40c5b94..f542cd8 100644
--- a/hacks/tessellimage.c
+++ b/hacks/tessellimage.c
@@ -364,7 +364,7 @@ analyze (struct state *st)
for (x = 0; x < st->delta->width; x++)
{
unsigned long p = XGetPixel (st->delta, x, y);
- if (p > sizeof(histo)) abort();
+ if (p >= sizeof(histo) / sizeof (*histo)) abort();
histo[p]++;
}
--
2.28.0