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

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

Category: Incorrect expression
Function: test_io_channels
Component: Tests
CID: 209371

Details:

843         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_NAME(TEST_TEMP, ch1),
844                      "TEST_ADC_1"),
845                  "label ch1");
846         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_NAME(TEST_TEMP, ch2),
847                      "TEST_ADC_2"),
848                  "label ch2");
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_1", "TEST_ADC_1")" is always 0 because ""TEST_ADC_1"" is compared against itself.
849         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL(TEST_TEMP),
850                      "TEST_ADC_1"),
851                  "label 0 implicit");
852    
853         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_IDX(0, 0),
854                      "TEST_ADC_1"),
847                      "TEST_ADC_2"),
848                  "label ch2");
849         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL(TEST_TEMP),
850                      "TEST_ADC_1"),
851                  "label 0 implicit");
852    
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_1", "TEST_ADC_1")" is always 0 because ""TEST_ADC_1"" is compared against itself.
853         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_IDX(0, 0),
854                      "TEST_ADC_1"),
855                  "inst label 0");
856         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_IDX(0, 1),
857                      "TEST_ADC_2"),
858                  "inst label 1");
840         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_IDX(TEST_TEMP, 1),
841                      "TEST_ADC_2"),
842                  "label 1");
843         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_NAME(TEST_TEMP, ch1),
844                      "TEST_ADC_1"),
845                  "label ch1");
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_2", "TEST_ADC_2")" is always 0 because ""TEST_ADC_2"" is compared against itself.
846         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_NAME(TEST_TEMP, ch2),
847                      "TEST_ADC_2"),
848                  "label ch2");
849         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL(TEST_TEMP),
850                      "TEST_ADC_1"),
851                  "label 0 implicit");
859         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_NAME(0, ch1),
860                      "TEST_ADC_1"),
861                  "inst ch1");
862         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_NAME(0, ch2),
863                      "TEST_ADC_2"),
864                  "inst ch2");
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_1", "TEST_ADC_1")" is always 0 because ""TEST_ADC_1"" is compared against itself.
865         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL(0),
866                      "TEST_ADC_1"),
867                  "inst ch1 implicit");
868    
869         zassert_equal(DT_IO_CHANNELS_INPUT_BY_IDX(TEST_TEMP, 0), 10, "input 0");
870         zassert_equal(DT_IO_CHANNELS_INPUT_BY_IDX(TEST_TEMP, 1), 20, "input 1");
853         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_IDX(0, 0),
854                      "TEST_ADC_1"),
855                  "inst label 0");
856         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_IDX(0, 1),
857                      "TEST_ADC_2"),
858                  "inst label 1");
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_1", "TEST_ADC_1")" is always 0 because ""TEST_ADC_1"" is compared against itself.
859         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_NAME(0, ch1),
860                      "TEST_ADC_1"),
861                  "inst ch1");
862         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_NAME(0, ch2),
863                      "TEST_ADC_2"),
864                  "inst ch2");
837         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_IDX(TEST_TEMP, 0),
838                      "TEST_ADC_1"),
839                  "label 0");
840         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_IDX(TEST_TEMP, 1),
841                      "TEST_ADC_2"),
842                  "label 1");
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_1", "TEST_ADC_1")" is always 0 because ""TEST_ADC_1"" is compared against itself.
843         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_NAME(TEST_TEMP, ch1),
844                      "TEST_ADC_1"),
845                  "label ch1");
846         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_NAME(TEST_TEMP, ch2),
847                      "TEST_ADC_2"),
848                  "label ch2");
856         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_IDX(0, 1),
857                      "TEST_ADC_2"),
858                  "inst label 1");
859         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_NAME(0, ch1),
860                      "TEST_ADC_1"),
861                  "inst ch1");
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_2", "TEST_ADC_2")" is always 0 because ""TEST_ADC_2"" is compared against itself.
862         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_NAME(0, ch2),
863                      "TEST_ADC_2"),
864                  "inst ch2");
865         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL(0),
866                      "TEST_ADC_1"),
867                  "inst ch1 implicit");
834     #define DT_DRV_COMPAT vnd_adc_temp_sensor
835     static void test_io_channels(void)
836     {
837         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_IDX(TEST_TEMP, 0),
838                      "TEST_ADC_1"),
839                  "label 0");
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_2", "TEST_ADC_2")" is always 0 because ""TEST_ADC_2"" is compared against itself.
840         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_IDX(TEST_TEMP, 1),
841                      "TEST_ADC_2"),
842                  "label 1");
843         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_NAME(TEST_TEMP, ch1),
844                      "TEST_ADC_1"),
845                  "label ch1");
850                      "TEST_ADC_1"),
851                  "label 0 implicit");
852    
853         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_IDX(0, 0),
854                      "TEST_ADC_1"),
855                  "inst label 0");
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_2", "TEST_ADC_2")" is always 0 because ""TEST_ADC_2"" is compared against itself.
856         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_IDX(0, 1),
857                      "TEST_ADC_2"),
858                  "inst label 1");
859         zassert_true(!strcmp(DT_INST_IO_CHANNELS_LABEL_BY_NAME(0, ch1),
860                      "TEST_ADC_1"),
861                  "inst ch1");
831     }
832    
833     #undef DT_DRV_COMPAT
834     #define DT_DRV_COMPAT vnd_adc_temp_sensor
835     static void test_io_channels(void)
836     {
>>>     CID 209371:    (CONSTANT_EXPRESSION_RESULT)
>>>     "strcmp("TEST_ADC_1", "TEST_ADC_1")" is always 0 because ""TEST_ADC_1"" is compared against itself.
837         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_IDX(TEST_TEMP, 0),
838                      "TEST_ADC_1"),
839                  "label 0");
840         zassert_true(!strcmp(DT_IO_CHANNELS_LABEL_BY_IDX(TEST_TEMP, 1),
841                      "TEST_ADC_2"),
842                  "label 1");

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