Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Coverity CID :209374] Pointless string comparison in tests/lib/devicetree/src/main.c #24035

Closed
zephyrbot opened this issue Apr 2, 2020 · 1 comment
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug

Comments

@zephyrbot
Copy link
Collaborator

Static code scan issues found in file:

https://github.com/zephyrproject-rtos/zephyr/tree/29c0c08fd4abc34aae4e1bf579cc506eaabef428/tests/lib/devicetree/src/main.c#L47

Category: Incorrect expression
Function: test_path_props
Component: Tests
CID: 209374

Details:

29                   "deadbeef reg[0] addr");
30         zassert_equal(DT_REG_SIZE(TEST_DEADBEEF), 0x1000,
31                   "deadbeef reg[0] len");
32         zassert_equal(DT_PROP(TEST_DEADBEEF, gpio_controller), 1,
33                   "deadbeef gpio-controller");
34         zassert_equal(DT_PROP(TEST_DEADBEEF, ngpios), 32, "deadbeef ngpios");
>>>     CID 209374:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("okay", "okay")" is always 0 because ""okay"" is compared against itself.
35         zassert_true(!strcmp(DT_PROP(TEST_DEADBEEF, status), "okay"),
36                  "deadbeef status");
37         zassert_equal(DT_PROP_LEN(TEST_DEADBEEF, compatible), 1,
38                   "deadbeef compatible len");
39         zassert_true(!strcmp(DT_PROP_BY_IDX(TEST_DEADBEEF, compatible, 0),
40                      "vnd,gpio"),
33                   "deadbeef gpio-controller");
34         zassert_equal(DT_PROP(TEST_DEADBEEF, ngpios), 32, "deadbeef ngpios");
35         zassert_true(!strcmp(DT_PROP(TEST_DEADBEEF, status), "okay"),
36                  "deadbeef status");
37         zassert_equal(DT_PROP_LEN(TEST_DEADBEEF, compatible), 1,
38                   "deadbeef compatible len");
>>>     CID 209374:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("vnd,gpio", "vnd,gpio")" is always 0 because ""vnd,gpio"" is compared against itself.
39         zassert_true(!strcmp(DT_PROP_BY_IDX(TEST_DEADBEEF, compatible, 0),
40                      "vnd,gpio"),
41                  "deadbeef compatible[0]");
42         zassert_true(DT_NODE_HAS_PROP(TEST_DEADBEEF, status),
43                  "deadbeef status");
44         zassert_false(DT_NODE_HAS_PROP(TEST_DEADBEEF, foobar),
18     #define TEST_PH    DT_NODELABEL(test_phandles)
19     #define TEST_IRQ    DT_NODELABEL(test_irq)
20     #define TEST_TEMP    DT_NODELABEL(test_temp_sensor)
21    
22     static void test_path_props(void)
23     {
>>>     CID 209374:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_GPIO_1", "TEST_GPIO_1")" is always 0 because ""TEST_GPIO_1"" is compared against itself.
24         zassert_true(!strcmp(DT_LABEL(TEST_DEADBEEF), "TEST_GPIO_1"),
25                  "deadbeef label != TEST_GPIO_1");
26         zassert_equal(DT_NUM_REGS(TEST_DEADBEEF), 1,
27                   "deadbeef num reg");
28         zassert_equal(DT_REG_ADDR(TEST_DEADBEEF), 0xdeadbeef,
29                   "deadbeef reg[0] addr");
52                  "abcd1234 gpio-controller");
53         zassert_equal(DT_PROP(TEST_ABCD1234, ngpios), 32, "abcd1234 ngpios");
54         zassert_true(!strcmp(DT_PROP(TEST_ABCD1234, status), "okay"),
55                  "abcd1234 status");
56         zassert_equal(DT_PROP_LEN(TEST_ABCD1234, compatible), 1,
57                   "abcd1234 compatible len");
>>>     CID 209374:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("vnd,gpio", "vnd,gpio")" is always 0 because ""vnd,gpio"" is compared against itself.
58         zassert_true(!strcmp(DT_PROP_BY_IDX(TEST_ABCD1234, compatible, 0),
59                      "vnd,gpio"),
60                  "abcd1234 compatible[0]");
61     }
62    
63     static void test_alias_props(void)
48                  "abcd1234 label != TEST_GPIO_2");
49         zassert_equal(DT_NUM_REGS(TEST_ABCD1234), 2,
50                   "abcd1234 num regs");
51         zassert_equal(DT_PROP(TEST_ABCD1234, gpio_controller), 1,
52                  "abcd1234 gpio-controller");
53         zassert_equal(DT_PROP(TEST_ABCD1234, ngpios), 32, "abcd1234 ngpios");
>>>     CID 209374:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("okay", "okay")" is always 0 because ""okay"" is compared against itself.
54         zassert_true(!strcmp(DT_PROP(TEST_ABCD1234, status), "okay"),
55                  "abcd1234 status");
56         zassert_equal(DT_PROP_LEN(TEST_ABCD1234, compatible), 1,
57                   "abcd1234 compatible len");
58         zassert_true(!strcmp(DT_PROP_BY_IDX(TEST_ABCD1234, compatible, 0),
59                      "vnd,gpio"),
41                  "deadbeef compatible[0]");
42         zassert_true(DT_NODE_HAS_PROP(TEST_DEADBEEF, status),
43                  "deadbeef status");
44         zassert_false(DT_NODE_HAS_PROP(TEST_DEADBEEF, foobar),
45                   "deadbeef foobar");
46    
>>>     CID 209374:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_GPIO_2", "TEST_GPIO_2")" is always 0 because ""TEST_GPIO_2"" is compared against itself.
47         zassert_true(!strcmp(DT_LABEL(TEST_ABCD1234), "TEST_GPIO_2"),
48                  "abcd1234 label != TEST_GPIO_2");
49         zassert_equal(DT_NUM_REGS(TEST_ABCD1234), 2,
50                   "abcd1234 num regs");
51         zassert_equal(DT_PROP(TEST_ABCD1234, gpio_controller), 1,
52                  "abcd1234 gpio-controller");

Please fix or provide comments in coverity using the link:

https://scan9.coverity.com/reports.htm#v32951/p12996.

Note: This issue was created automatically. Priority was set based on classification
of the file affected and the impact field in coverity. Assignees were set using the CODEOWNERS file.

@zephyrbot zephyrbot added bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug labels Apr 2, 2020
@nashif nashif assigned mbolivar-nordic and unassigned nashif Apr 2, 2020
@galak
Copy link
Collaborator

galak commented Apr 2, 2020

False positive, this is what the test is trying to do.

@galak galak closed this as completed Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

4 participants