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: 236000] Improper use of negative value in tests/lib/cbprintf_package/src/test.inc #35115

Closed
zephyrbot opened this issue May 11, 2021 · 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
Milestone

Comments

@zephyrbot
Copy link
Collaborator

Static code scan issues found in file:

https://github.com/zephyrproject-rtos/zephyr/tree/0622bde3bf22926544c1aaef4c01dfa23d79f26e/tests/lib/cbprintf_package/src/test.inc#L114

Category: Integer handling issues
Function: test_cbprintf_package
Component: Tests
CID: 236000

Details:

https://github.com/zephyrproject-rtos/zephyr/blob/0622bde3bf22926544c1aaef4c01dfa23d79f26e/tests/lib/cbprintf_package/src/test.inc

114      TEST_PACKAGING("test long %x %lx %x", 0xb1b2b3b4, li, 0xe4e3e2e1);
115      TEST_PACKAGING("test long long %x %llx %x", 0xb1b2b3b4, lli, 0xe4e3e2e1);
116     
117      /* tests with varied elements */
118      TEST_PACKAGING("test %d %hd %hhd", i, s, sc);
119      TEST_PACKAGING("test %ld %llx %hhu %hu %u", li, lli, uc, us, ui);
>>>     CID 236000:    (NEGATIVE_RETURNS)
>>>     "len" is passed to a parameter that cannot be negative.
120      TEST_PACKAGING("test %lu %llu", ul, ull);
121      TEST_PACKAGING("test %c %p", c, vp);
122     
123      if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) {
124              float f = -1.234;
125              double d = 1.2333;
115      TEST_PACKAGING("test long long %x %llx %x", 0xb1b2b3b4, lli, 0xe4e3e2e1);
116     
117      /* tests with varied elements */
118      TEST_PACKAGING("test %d %hd %hhd", i, s, sc);
119      TEST_PACKAGING("test %ld %llx %hhu %hu %u", li, lli, uc, us, ui);
120      TEST_PACKAGING("test %lu %llu", ul, ull);
>>>     CID 236000:    (NEGATIVE_RETURNS)
>>>     "len" is passed to a parameter that cannot be negative.
121      TEST_PACKAGING("test %c %p", c, vp);
122     
123      if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) {
124              float f = -1.234;
125              double d = 1.2333;
126     
112     
113      /* tests to exercize different element alignments */
114      TEST_PACKAGING("test long %x %lx %x", 0xb1b2b3b4, li, 0xe4e3e2e1);
115      TEST_PACKAGING("test long long %x %llx %x", 0xb1b2b3b4, lli, 0xe4e3e2e1);
116     
117      /* tests with varied elements */
>>>     CID 236000:    (NEGATIVE_RETURNS)
>>>     "len" is passed to a parameter that cannot be negative.
118      TEST_PACKAGING("test %d %hd %hhd", i, s, sc);
119      TEST_PACKAGING("test %ld %llx %hhu %hu %u", li, lli, uc, us, ui);
120      TEST_PACKAGING("test %lu %llu", ul, ull);
121      TEST_PACKAGING("test %c %p", c, vp);
122     
123      if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) {
109      unsigned long long ull = 0xaabbaabbaabb;
110      void *vp = NULL;
111     
112     
113      /* tests to exercize different element alignments */
114      TEST_PACKAGING("test long %x %lx %x", 0xb1b2b3b4, li, 0xe4e3e2e1);
>>>     CID 236000:    (NEGATIVE_RETURNS)
>>>     "len" is passed to a parameter that cannot be negative.
115      TEST_PACKAGING("test long long %x %llx %x", 0xb1b2b3b4, lli, 0xe4e3e2e1);
116     
117      /* tests with varied elements */
118      TEST_PACKAGING("test %d %hd %hhd", i, s, sc);
119      TEST_PACKAGING("test %ld %llx %hhu %hu %u", li, lli, uc, us, ui);
120      TEST_PACKAGING("test %lu %llu", ul, ull);
113      /* tests to exercize different element alignments */
114      TEST_PACKAGING("test long %x %lx %x", 0xb1b2b3b4, li, 0xe4e3e2e1);
115      TEST_PACKAGING("test long long %x %llx %x", 0xb1b2b3b4, lli, 0xe4e3e2e1);
116     
117      /* tests with varied elements */
118      TEST_PACKAGING("test %d %hd %hhd", i, s, sc);
>>>     CID 236000:    (NEGATIVE_RETURNS)
>>>     "len" is passed to a parameter that cannot be negative.
119      TEST_PACKAGING("test %ld %llx %hhu %hu %u", li, lli, uc, us, ui);
120      TEST_PACKAGING("test %lu %llu", ul, ull);
121      TEST_PACKAGING("test %c %p", c, vp);
122     
123      if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT)) {
124              float f = -1.234;
108      unsigned long ul = 0xaabbaabb;
109      unsigned long long ull = 0xaabbaabbaabb;
110      void *vp = NULL;
111     
112     
113      /* tests to exercize different element alignments */
>>>     CID 236000:    (NEGATIVE_RETURNS)
>>>     "len" is passed to a parameter that cannot be negative.
114      TEST_PACKAGING("test long %x %lx %x", 0xb1b2b3b4, li, 0xe4e3e2e1);
115      TEST_PACKAGING("test long long %x %llx %x", 0xb1b2b3b4, lli, 0xe4e3e2e1);
116     
117      /* tests with varied elements */
118      TEST_PACKAGING("test %d %hd %hhd", i, s, sc);
119      TEST_PACKAGING("test %ld %llx %hhu %hu %u", li, lli, uc, us, ui);

Please fix or provide comments in coverity using the link:

https://scan9.coverity.com/reports.htm#v29271/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 May 11, 2021
@galak galak added this to the v2.6.0 milestone May 11, 2021
@nordic-krch
Copy link
Contributor

False positive, earlier assertion in the test will return from the test if rc is negative.

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

3 participants