]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
clang: additional fixes detected by clang analyzer
authorVincent Bernat <bernat@luffy.cx>
Sun, 13 Jan 2013 10:02:28 +0000 (11:02 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sun, 13 Jan 2013 10:02:28 +0000 (11:02 +0100)
src/client/commands.c
src/daemon/edp.c
src/daemon/interfaces-linux.c
src/daemon/lldpd.c
src/marshal.c
src/marshal.h

index 96a81227f238b713ea115fe161ecb9af08b4d5eb..be30b723a0c42f0a582a300b15f83cedc7a4fa78 100644 (file)
@@ -400,19 +400,22 @@ end:
                TAILQ_HEAD(, candidate_word) words; /* List of subnodes */
                TAILQ_INIT(&words);
                current = cmdenv_top(&env);
-               TAILQ_FOREACH(candidate, &current->subentries, next) {
-                       if ((!candidate->token || help ||
-                               !strncmp(env.argv[env.argc - 1], candidate->token,
-                                   strlen(env.argv[env.argc -1 ]))) &&
-                           (!candidate->validate ||
-                               candidate->validate(&env, candidate->arg) == 1)) {
-                               struct candidate_word *cword = malloc(sizeof(struct candidate_word));
-                               if (!cword) break;
-                               cword->word = candidate->token;
-                               cword->doc = candidate->doc;
-                               if (cword->word && strlen(cword->word) > maxl)
-                                       maxl = strlen(cword->word);
-                               TAILQ_INSERT_TAIL(&words, cword, next);
+               if (!TAILQ_EMPTY(&current->subentries)) {
+                       TAILQ_FOREACH(candidate, &current->subentries, next) {
+                               if ((!candidate->token || help ||
+                                       !strncmp(env.argv[env.argc - 1], candidate->token,
+                                           strlen(env.argv[env.argc -1 ]))) &&
+                                   (!candidate->validate ||
+                                       candidate->validate(&env, candidate->arg) == 1)) {
+                                       struct candidate_word *cword =
+                                           malloc(sizeof(struct candidate_word));
+                                       if (!cword) break;
+                                       cword->word = candidate->token;
+                                       cword->doc = candidate->doc;
+                                       if (cword->word && strlen(cword->word) > maxl)
+                                               maxl = strlen(cword->word);
+                                       TAILQ_INSERT_TAIL(&words, cword, next);
+                               }
                        }
                }
                if (!TAILQ_EMPTY(&words)) {
index 063ed4669548096cd4976c02c40dc22c6f501b5f..326d1940d6a4947dc5d29bf5bd4e306fc08f1d65 100644 (file)
@@ -503,7 +503,9 @@ edp_decode(struct lldpd *cfg, char *frame, int s,
        return 1;
 
 malformed:
+#ifdef ENABLE_DOT1
        free(lvlan);
+#endif
        lldpd_chassis_cleanup(chassis, 1);
        lldpd_port_cleanup(port, 1);
        free(port);
index 3a0bc30d93a701ff8f889ec421cf104338ddeb33..021e41c764c55aa807b5aacd4a9a3321a7424670 100644 (file)
@@ -94,7 +94,7 @@ iflinux_eth_recv(struct lldpd *cfg, struct lldpd_hardware *hardware,
     int fd, char *buffer, size_t size)
 {
        int n;
-       struct sockaddr_ll from;
+       struct sockaddr_ll from = {};
        socklen_t fromlen;
 
        log_debug("interfaces", "receive PDU from ethernet device %s",
@@ -528,7 +528,7 @@ iface_bond_recv(struct lldpd *cfg, struct lldpd_hardware *hardware,
     int fd, char *buffer, size_t size)
 {
        int n;
-       struct sockaddr_ll from;
+       struct sockaddr_ll from = {};
        socklen_t fromlen;
        struct bond_master *master = hardware->h_data;
 
index 9833891fe071501c9dbf43e057ff0829f70f5cb8..9f968cd1e65f3e55161b2dd9bb6a59dbbeb43d4c 100644 (file)
@@ -876,6 +876,7 @@ lldpd_update_localchassis(struct lldpd *cfg)
        char *hp;
 
        log_debug("localchassis", "update information for local chassis");
+       assert(LOCAL_CHASSIS(cfg) != NULL);
 
        /* Set system name and description */
        if (uname(&un) != 0)
index 238be97057abac9d4f66d540520fe1c80e046b13..251a2b50386161c8990f9ec430cd1a5df818487f 100644 (file)
@@ -130,7 +130,7 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input,
        for (current = mi->pointers; current->mi; current++) {
                size_t sublen;
                void  *source;
-               void  *target;
+               void  *target = NULL;
                if (current->kind == ignore) continue;
                if (current->kind == pointer) {
                        memcpy(&source,
@@ -144,9 +144,10 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input,
                sublen = marshal_serialize_(current->mi,
                    source, &target,
                    current->kind == substruct, refs, osize);
-               if (sublen == -1) {
+               if (sublen == -1 || target == NULL) {
                        log_warnx("marshal", "unable to serialize substructure %s for %s",
                            current->mi->name, mi->name);
+                       free(target);
                        free(serialized);
                        return -1;
                }
index 22c432afd8f66569fee566e84f9b873187c1b199..0c4ad69b0e0068b329f0ca078e5fe379c9c088ef 100644 (file)
@@ -106,11 +106,13 @@ extern struct marshal_info marshal_info_ignore;
        MARSHAL_END
 
 /* Serialization */
-ssize_t  marshal_serialize_(struct marshal_info *, void *, void **, int, void *, int);
+ssize_t  marshal_serialize_(struct marshal_info *, void *, void **, int, void *, int)
+       __attribute__((nonnull (1, 2, 3) ));
 #define marshal_serialize(type, o, output) marshal_serialize_(&MARSHAL_INFO(type), o, output, 0, NULL, 0)
 
 /* Unserialization */
-size_t  marshal_unserialize_(struct marshal_info *, void *, size_t, void **, void*, int, int);
+size_t  marshal_unserialize_(struct marshal_info *, void *, size_t, void **, void*, int, int)
+       __attribute__((nonnull (1, 2, 4) ));
 #define marshal_unserialize(type, o, l, input) \
        marshal_unserialize_(&MARSHAL_INFO(type), o, l, input, NULL, 0, 0)