misra User - 2021-12-03

Hello,

I have recently started to use cppcheck with misra addons and it's great!

I just have a minor false positive on rule 15.2.
Here is a snippet to reproduce:

struct {
    int id;
    int len;
} my_struct;

static int func1(const char *hostname)
{
    if (strlen(hostname) != 0) {
        goto error;
    }

    return 0;

error:
    return -1;
}

static int func2(const char *hostname)
{
    int ret = strlen(hostname);

    if (ret == 3) {
        ret = -3;
        goto error;
    }

    if (ret == 4) {
        ret = -4;
        goto error_2;
    }

    struct my_struct msg = {
        .id = ret,
        .len = 2,
    };

    if ((msg.len * ret) > 10) {
        ret = -10;
        goto error_2;
    }
    return 0;

error_2:
    ret *= 3;

error:
    return ret;
}

This produce :

Checking misra_15_2.c.dump...
Checking misra_15_2.c.dump, config ...
[misra_15_2.c:4] (style) misra violation (use --rule-texts=<file> to get proper output) (Undefined) [misra-c2012-8.4]
[misra_15_2.c:8] (style) misra violation (use --rule-texts=<file> to get proper output) (Undefined) [misra-c2012-10.4]
[misra_15_2.c:9] (style) misra violation (use --rule-texts=<file> to get proper output) (Undefined) [misra-c2012-15.1]
[misra_15_2.c:24] (style) misra violation (use --rule-texts=<file> to get proper output) (Undefined) [misra-c2012-15.1]
[misra_15_2.c:29] (style) misra violation (use --rule-texts=<file> to get proper output) (Undefined) [misra-c2012-15.1]
[misra_15_2.c:39] (style) misra violation (use --rule-texts=<file> to get proper output) (Undefined) [misra-c2012-15.1]
[misra_15_2.c:24] (style) misra violation (use --rule-texts=<file> to get proper output) (Undefined) [misra-c2012-15.2]
[misra_15_2.c:29] (style) misra violation (use --rule-texts=<file> to get proper output) (Undefined) [misra-c2012-15.2]

MISRA rules violations found:
        Undefined: 8

MISRA rules violated:
        misra-c2012-8.4 (-): 1
        misra-c2012-10.4 (-): 1
        misra-c2012-15.1 (-): 4
        misra-c2012-15.2 (-): 2

The 15.2 violations should not appear as the goto labels are correctly defined later in the same function.

Thanks,

Xavier