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 :209372] Pointless string comparison in tests/lib/devicetree/src/main.c #24037

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#L811

Category: Incorrect expression
Function: test_gpio
Component: Tests
CID: 209372

Details:

766     #undef DT_DRV_COMPAT
767     #define DT_DRV_COMPAT vnd_phandle_holder
768     static void test_gpio(void)
769     {
770    
771         /* DT_GPIO_LABEL_BY_IDX */
>>>     CID 209372:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_GPIO_1", "TEST_GPIO_1")" is always 0 because ""TEST_GPIO_1"" is compared against itself.
772         zassert_true(!strcmp(DT_GPIO_LABEL_BY_IDX(TEST_PH, gpios, 0),
773                      "TEST_GPIO_1"),
774                  "gpio 0 name idx");
775         zassert_true(!strcmp(DT_GPIO_LABEL_BY_IDX(TEST_PH, gpios, 1),
776                      "TEST_GPIO_2"),
777                  "gpio 1 name idx");
774                  "gpio 0 name idx");
775         zassert_true(!strcmp(DT_GPIO_LABEL_BY_IDX(TEST_PH, gpios, 1),
776                      "TEST_GPIO_2"),
777                  "gpio 1 name idx");
778    
779         /* DT_GPIO_LABEL */
>>>     CID 209372:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_GPIO_1", "TEST_GPIO_1")" is always 0 because ""TEST_GPIO_1"" is compared against itself.
780         zassert_true(!strcmp(DT_GPIO_LABEL(TEST_PH, gpios), "TEST_GPIO_1"),
781                  "gpio 0 name");
782    
783         /* DT_GPIO_PIN_BY_IDX */
784         zassert_equal(DT_GPIO_PIN_BY_IDX(TEST_PH, gpios, 0), 10, "gpio 0 pin idx");
785         zassert_equal(DT_GPIO_PIN_BY_IDX(TEST_PH, gpios, 1), 30, "gpio 1 pin idx");
769     {
770    
771         /* DT_GPIO_LABEL_BY_IDX */
772         zassert_true(!strcmp(DT_GPIO_LABEL_BY_IDX(TEST_PH, gpios, 0),
773                      "TEST_GPIO_1"),
774                  "gpio 0 name idx");
>>>     CID 209372:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_GPIO_2", "TEST_GPIO_2")" is always 0 because ""TEST_GPIO_2"" is compared against itself.
775         zassert_true(!strcmp(DT_GPIO_LABEL_BY_IDX(TEST_PH, gpios, 1),
776                      "TEST_GPIO_2"),
777                  "gpio 1 name idx");
778    
779         /* DT_GPIO_LABEL */
780         zassert_true(!strcmp(DT_GPIO_LABEL(TEST_PH, gpios), "TEST_GPIO_1"),
797         zassert_equal(DT_GPIO_FLAGS(TEST_PH, gpios), 20, "gpio 0 flags");
798    
799         /* DT_INST */
800         zassert_equal(DT_NUM_INST(DT_DRV_COMPAT), 1, "one instance");
801    
802         /* DT_INST_GPIO_LABEL_BY_IDX */
>>>     CID 209372:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_GPIO_1", "TEST_GPIO_1")" is always 0 because ""TEST_GPIO_1"" is compared against itself.
803         zassert_true(!strcmp(DT_INST_GPIO_LABEL_BY_IDX(0, gpios, 0),
804                      "TEST_GPIO_1"),
805                  "gpio inst 0 name idx");
806         zassert_true(!strcmp(DT_INST_GPIO_LABEL_BY_IDX(0, gpios, 1),
807                      "TEST_GPIO_2"),
808                  "gpio inst 1 name idx");
800         zassert_equal(DT_NUM_INST(DT_DRV_COMPAT), 1, "one instance");
801    
802         /* DT_INST_GPIO_LABEL_BY_IDX */
803         zassert_true(!strcmp(DT_INST_GPIO_LABEL_BY_IDX(0, gpios, 0),
804                      "TEST_GPIO_1"),
805                  "gpio inst 0 name idx");
>>>     CID 209372:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_GPIO_2", "TEST_GPIO_2")" is always 0 because ""TEST_GPIO_2"" is compared against itself.
806         zassert_true(!strcmp(DT_INST_GPIO_LABEL_BY_IDX(0, gpios, 1),
807                      "TEST_GPIO_2"),
808                  "gpio inst 1 name idx");
809    
810         /* DT_INST_GPIO_LABEL */
811         zassert_true(!strcmp(DT_INST_GPIO_LABEL(0, gpios), "TEST_GPIO_1"),
805                  "gpio inst 0 name idx");
806         zassert_true(!strcmp(DT_INST_GPIO_LABEL_BY_IDX(0, gpios, 1),
807                      "TEST_GPIO_2"),
808                  "gpio inst 1 name idx");
809    
810         /* DT_INST_GPIO_LABEL */
>>>     CID 209372:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_GPIO_1", "TEST_GPIO_1")" is always 0 because ""TEST_GPIO_1"" is compared against itself.
811         zassert_true(!strcmp(DT_INST_GPIO_LABEL(0, gpios), "TEST_GPIO_1"),
812                  "gpio inst 0 name");
813    
814         /* DT_INST_GPIO_PIN_BY_IDX */
815         zassert_equal(DT_INST_GPIO_PIN_BY_IDX(0, gpios, 0),
816                   10, "gpio inst 0 pin idx");

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