]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/examples_exist.c
ccanlint: check unused result.
[ccan] / tools / ccanlint / tests / examples_exist.c
index e308be20ec76289bab821fe77c19f9413eab8f63..61359596e1f693ed56a127c613724462e1f1f2d7 100644 (file)
@@ -45,7 +45,10 @@ static char *add_example(struct manifest *m, struct ccan_file *source,
        /* Add #line to demark where we are from, so errors are correct! */
        linemarker = tal_fmt(f, "#line %i \"%s\"\n",
                             example->srcline+2, source->fullname);
-       write(fd, linemarker, strlen(linemarker));
+       if (write(fd, linemarker, strlen(linemarker)) != (int)strlen(linemarker)) {
+               close(fd);
+               return cast_const(char *, "Failure writing to temporary file");
+       }
 
        for (i = 0; i < example->num_lines; i++) {
                if (write(fd, example->lines[i], strlen(example->lines[i]))
@@ -62,7 +65,7 @@ static char *add_example(struct manifest *m, struct ccan_file *source,
 
 /* FIXME: We should have one example per function in header. */
 static void extract_examples(struct manifest *m,
-                            unsigned int *timeleft,
+                            unsigned int *timeleft UNNEEDED,
                             struct score *score)
 {
        struct ccan_file *f, *mainh = NULL; /* gcc complains uninitialized */
@@ -79,13 +82,12 @@ static void extract_examples(struct manifest *m,
                }
        }
 
-       /* Check main header. */
+       /* Check all headers for examples. */
        list_for_each(&m->h_files, f, list) {
-               if (!strstarts(f->name, m->basename)
-                   || strlen(f->name) != strlen(m->basename) + 2)
-                       continue;
+               if (strstarts(f->name, m->basename)
+                   && strlen(f->name) == strlen(m->basename) + 2)
+                       mainh = f;
 
-               mainh = f;
                list_for_each(get_ccan_file_docs(f), d, list) {
                        if (streq(d->type, "example")) {
                                score->error = add_example(m, f, d);
@@ -115,7 +117,7 @@ struct ccanlint examples_exist = {
        .key = "examples_exist",
        .name = "_info and main header file have Example: sections",
        .check = extract_examples,
-       .needs = "info_exists"
+       .needs = "info_exists main_header_exists"
 };
 
 REGISTER_TEST(examples_exist);