]> git.neil.brown.name Git - edlib.git/commitdiff
Fix assorted smatch warnings.
authorNeilBrown <neil@brown.name>
Sat, 6 Jul 2019 07:15:00 +0000 (17:15 +1000)
committerNeilBrown <neil@brown.name>
Fri, 19 Jul 2019 21:59:08 +0000 (07:59 +1000)
No really bugs here.
I guess I need to re-enable smatch on my desktop

Signed-off-by: NeilBrown <neil@brown.name>
core-keymap.c
core-misc.c
doc-text.c
lib-tile.c
misc.h
render-complete.c

index baa7ea51c02bb8bede2b8ffbc783aa523a2da0dc..70b9bc930e8ad4d8570e239e1285917fc3b38c2c 100644 (file)
@@ -393,7 +393,7 @@ int key_lookup(struct map *m safe, const struct cmd_info *ci safe)
        }
 
        comm = key_lookup_cmd(m, ci->key, &key, &len);
-       if (comm == NULL) {
+       if (comm == NULL || key == NULL) {
                stat_count("bloom-hit-bad");
                return Efallthrough;
        } else {
index 74b3987ed342a45854bffc623794267d01574c5b..6d90ee31955902ba13cfd5e51fefcbab18f68c86 100644 (file)
@@ -163,7 +163,8 @@ static int hash_str(char *key safe, int len)
 {
        int i;
        int h = 0;
-for (i = 0; (len < 0 || i < len) && key[i]; i++)
+
+       for (i = 0; (len < 0 || i < len) && key[i]; i++)
                h = qhash(key[i], h);
        return h;
 }
@@ -184,7 +185,7 @@ struct kstack {
 } kstack[20];
 int ktos = 0;
 
-void time_start_key(char *key)
+void time_start_key(char *key safe)
 {
        struct timespec start;
 
@@ -198,7 +199,7 @@ void time_start_key(char *key)
        kstack[ktos-1].name = key;
 }
 
-static struct khash *hash_find(struct khash **table, char *key)
+static struct khash *hash_find(struct khash **table, char *key safe)
 {
        struct khash *h, **hp;
        int hash;
@@ -219,7 +220,7 @@ static struct khash *hash_find(struct khash **table, char *key)
        return h;
 }
 
-void time_stop_key(char *key)
+void time_stop_key(char *key safe)
 {
        struct timespec stop;
        struct khash *h;
@@ -268,7 +269,7 @@ static void dump_key_hash(void)
 
 struct khash *count_tab[1024];
 
-void stat_count(char *name)
+void stat_count(char *name safe)
 {
        struct khash *h;
 
@@ -303,7 +304,7 @@ static void dump_count_hash(void)
        fprintf(dump_file, " nhash:%d:%d:%d", cnt, buckets, max);
 }
 
-static void hash_free(struct khash **tab)
+static void hash_free(struct khash **tab safe)
 {
        int i;
 
index 7baeac66cacf6c1c73dae21137a4ce955634a709..c52441501de0a3026063eea070f47208e751c550 100644 (file)
@@ -907,7 +907,7 @@ static void text_del(struct text *t safe, struct doc_ref *pos safe, int len,
  * both start and end will point to a NULL chunk.
  * When undoing a split, both will be at the point of the split.
  */
-static void text_undo(struct text *t safe, struct text_edit *e,
+static void text_undo(struct text *t safe, struct text_edit *e safe,
                       struct doc_ref *start safe, struct doc_ref *end safe)
 {
        if (e->len == 0)
@@ -968,7 +968,7 @@ static void text_undo(struct text *t safe, struct text_edit *e,
        }
 }
 
-static void text_redo(struct text *t safe, struct text_edit *e,
+static void text_redo(struct text *t safe, struct text_edit *e safe,
                       struct doc_ref *start safe, struct doc_ref *end safe)
 {
        int is_split = 0;
@@ -2003,7 +2003,7 @@ DEF_CMD(text_modified)
        return 1;
 }
 
-static void text_cleanout(struct text *t)
+static void text_cleanout(struct text *t safe)
 {
        struct text_alloc *ta;
        struct mark *m;
@@ -2025,7 +2025,7 @@ static void text_cleanout(struct text *t)
                ta = tmp->prev;
                free(tmp);
        }
-       t->alloc = NULL;
+       t->alloc = safe_cast NULL;
        while (t->undo) {
                struct text_edit *te = t->undo;
                t->undo = te->next;
index f0fb6d34a17ae7f18eaa2fbb53b74a572d0cea02..e8a9ba38c911b913417394508d85de90c9b4feb1 100644 (file)
@@ -875,6 +875,8 @@ DEF_CMD(tile_other)
        if (!ti->leaf) {
                /* probably coming from a pop-up. Just use first tile */
                ti2 = tile_first(ti);
+               if (!ti2)
+                       return Einval;
                if (ci->str2 && ti2->name && strcmp(ci->str2, ti2->name) == 0)
                        return Einval;
                return comm_call(ci->comm2, "callback:pane", ti2->p);
diff --git a/misc.h b/misc.h
index 81481f77a9407a0ddd8886ca9f2a32ec2db64c83..83aa855b8ca8e0438fe77ea6af420e84fc1b5eec 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -40,9 +40,9 @@ enum timetype {
 };
 void time_start(enum timetype);
 void time_stop(enum timetype);
-void time_start_key(char *key);
-void time_stop_key(char *key);
+void time_start_key(char *key safe);
+void time_stop_key(char *key safe);
 
-void stat_count(char *name);
+void stat_count(char *name safe);
 
 void stat_free(void);
index fd6c6c0e81004b6491fa6bb4e14216910d9d0f90..011cce036a6cbe7de6686746a7fd129409437c1c 100644 (file)
@@ -328,8 +328,10 @@ DEF_CMD(complete_set_prefix)
                char *match = c;
                if (!cd->prefix_only)
                        match = strstr(match, cd->prefix);
+               if (!match)
+                       break;
                l = strlen(match);
-               if (match[l-1] == '\n')
+               if (l && match[l-1] == '\n')
                        l -= 1;
                if (common == NULL)
                        common = strndup(match, l);