Powered by Linux
noreturn attribute doesn't work in smatch — Semantic Matching Tool

noreturn attribute doesn't work in smatch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



./smatch: a.c:20 main() error: double free of 'str'

given:

```
#include <stdlib.h>
#include <string.h>

__attribute__((__noreturn__)) void
die(void)
{
        exit(1);
}

int
main(void)
{
        char *str = strdup("test");

        if (str != NULL) {
                free(str);
                die();
        }

        free(str);

        return (0);
}
```

As far as I can figure out, this looks like a sparse problem: an
'inline' or 'extern' specifier in this position gets marked as the
relevant MOD_* flag for the function, but the noreturn doesn't bubble
up in the same way. Some quick lame attempts to add ctx->is_noreturn did
not go well.

I think this might be the underlying issue behind sparse's failing test
validation/function-redecl2.c but I'm not positive.

We can do:

```
#ifdef __CHECKER__
#define SMATCH_NORETURN __attribute__((__noreturn__))
#else
#define SMATCH_NORETURN /* would break gcc otherwise */
#endif

__attribute__((__noreturn__)) void
die(void) SMATCH_NORETURN
{
```

but it's ... unlovely.

Any thoughts?

thanks
john



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux