From 5e5fd214b521b77d424bb797f98eb46804fcfe9b Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Sat, 22 Feb 2020 01:15:43 +0400 Subject: [PATCH] [iksemel, libdingaling] scan-build: fix multiple dead assignments and dereference of null pointer --- libs/iksemel/src/ikstack.c | 2 +- libs/iksemel/src/sax.c | 6 ------ libs/iksemel/test/tst-ikstack.c | 2 +- libs/iksemel/test/tst-sax.c | 2 +- libs/iksemel/tools/hash.c | 2 +- libs/iksemel/tools/iksperf.c | 3 +-- libs/libdingaling/src/libdingaling.c | 2 +- 7 files changed, 6 insertions(+), 13 deletions(-) diff --git a/libs/iksemel/src/ikstack.c b/libs/iksemel/src/ikstack.c index 9771a41e8b..b5fd75ef68 100644 --- a/libs/iksemel/src/ikstack.c +++ b/libs/iksemel/src/ikstack.c @@ -32,7 +32,7 @@ static ikschunk * find_space (ikstack *s, ikschunk *c, size_t size) { /* FIXME: dont use *2 after over allocated chunks */ - while (1) { + while (c) { if (c->size - c->used >= size) return c; if (!c->next) { if ((c->size * 2) > size) size = c->size * 2; diff --git a/libs/iksemel/src/sax.c b/libs/iksemel/src/sax.c index 338a5cf7f9..beb3621588 100644 --- a/libs/iksemel/src/sax.c +++ b/libs/iksemel/src/sax.c @@ -213,22 +213,16 @@ sax_core (iksparser *prs, char *buf, int len) goto cont; } else { if (c & 0x80) { - unsigned char mask; if ((c & 0x60) == 0x40) { prs->uni_max = 2; - mask = 0x1F; } else if ((c & 0x70) == 0x60) { prs->uni_max = 3; - mask = 0x0F; } else if ((c & 0x78) == 0x70) { prs->uni_max = 4; - mask = 0x07; } else if ((c & 0x7C) == 0x78) { prs->uni_max = 5; - mask = 0x03; } else if ((c & 0x7E) == 0x7C) { prs->uni_max = 6; - mask = 0x01; } else { return IKS_BADXML; } diff --git a/libs/iksemel/test/tst-ikstack.c b/libs/iksemel/test/tst-ikstack.c index 1a761ad708..d123e20047 100644 --- a/libs/iksemel/test/tst-ikstack.c +++ b/libs/iksemel/test/tst-ikstack.c @@ -36,7 +36,7 @@ test_stack (int cs) memset (mem, 'x', i); old = iks_stack_strcat (s, old, 0, buf + i, 1); } - if (strcmp (old, buf) != 0) { + if (old && strcmp (old, buf) != 0) { printf ("ikstack strcat bug:\nExpected: %s\n Result: %s\n", buf, old); exit (1); } diff --git a/libs/iksemel/test/tst-sax.c b/libs/iksemel/test/tst-sax.c index 77a5c13e95..c0a041aee1 100644 --- a/libs/iksemel/test/tst-sax.c +++ b/libs/iksemel/test/tst-sax.c @@ -160,7 +160,7 @@ tagHook (void *udata, char *name, char **atts, int type) nr = tester.cur->nr_atts; while (nr) { flag = 0; - for (i = 0;atts[i]; i+= 2) { + for (i = 0;atts&&atts[i]; i+= 2) { if (iks_strcmp (atts[i], tester.cur->atts[nr-1]) == 0 && iks_strcmp (atts[i+1], tester.cur->vals[nr-1]) == 0) { flag = 1; break; diff --git a/libs/iksemel/tools/hash.c b/libs/iksemel/tools/hash.c index 8ba83a0eea..c4b1179a87 100644 --- a/libs/iksemel/tools/hash.c +++ b/libs/iksemel/tools/hash.c @@ -117,7 +117,7 @@ hash_print (hash *h, char *title_fmt, char *line_fmt) struct item **tags, *t; unsigned int i = 0, pos = 0; - tags = calloc (sizeof (struct tag *), h->count); + tags = calloc (sizeof (struct item *), h->count); for (; i < h->size; i ++) { for (t = h->table[i]; t; t = t->next) { diff --git a/libs/iksemel/tools/iksperf.c b/libs/iksemel/tools/iksperf.c index 81e98ad1c4..4bcd4b3e57 100644 --- a/libs/iksemel/tools/iksperf.c +++ b/libs/iksemel/tools/iksperf.c @@ -207,7 +207,6 @@ serialize_test (char *buf, int len) unsigned long time; iks *x; iksparser *prs; - char *xml; int err; prs = iks_dom_new (&x); @@ -228,7 +227,7 @@ serialize_test (char *buf, int len) t_reset (); - xml = iks_string (iks_stack (x), x); + iks_string (iks_stack (x), x); time = t_elapsed (); diff --git a/libs/libdingaling/src/libdingaling.c b/libs/libdingaling/src/libdingaling.c index 07e70d0c50..6fbedfda6e 100644 --- a/libs/libdingaling/src/libdingaling.c +++ b/libs/libdingaling/src/libdingaling.c @@ -930,7 +930,7 @@ static int on_disco_default(void *user_data, ikspak *pak) char *node = NULL; char *ns = NULL; ldl_handle_t *handle = user_data; - iks *iq, *query, *tag; + iks *iq = NULL, *query, *tag; uint8_t send = 0; int x;