Skip to content

Commit dad1a68

Browse files
committed
posix.cfg: Fixed FP bufferOverlap-warning of bcopy() and added more tests.
1 parent 1fb1b22 commit dad1a68

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

cfg/posix.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3935,11 +3935,11 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
39353935
</arg>
39363936
<warn severity="style" reason="Obsolescent" alternatives="scalbln,scalblnf,scalbln,scalbn,scalbnf,scalbnl"/>
39373937
</function>
3938+
<!-- https://man7.org/linux/man-pages/man3/bcopy.3.html -->
39383939
<!-- void bcopy(const void *s1, void *s2, size_t n); -->
39393940
<function name="bcopy">
39403941
<noreturn>false</noreturn>
39413942
<leak-ignore/>
3942-
<not-overlapping-data ptr1-arg="1" ptr2-arg="2" size-arg="3"/>
39433943
<arg nr="1" direction="in">
39443944
<not-null/>
39453945
<not-uninit/>

test/cfg/posix.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,20 @@ void overlappingWriteFunction_bcopy(char *buf, const size_t count)
300300
// cppcheck-suppress bcopyCalled
301301
bcopy(&buf[0], &buf[3], 3U); // no-overlap
302302
// cppcheck-suppress bcopyCalled
303-
// cppcheck-suppress overlappingWriteFunction
304-
bcopy(&buf[0], &buf[3], 4U);
303+
bcopy(&buf[0], &buf[3], 4U); // The result is correct, even when both areas overlap.
304+
}
305+
306+
void nullPointer_bcopy(const void *src, void *dest, size_t n)
307+
{
308+
// No warning shall be shown:
309+
// cppcheck-suppress bcopyCalled
310+
bcopy(src, dest, n);
311+
// cppcheck-suppress bcopyCalled
312+
// cppcheck-suppress nullPointer
313+
bcopy(NULL, dest, n);
314+
// cppcheck-suppress bcopyCalled
315+
// cppcheck-suppress nullPointer
316+
bcopy(src, NULL, n);
305317
}
306318

307319
void overlappingWriteFunction_memccpy(unsigned char *src, unsigned char *dest, int c, size_t count)

0 commit comments

Comments
 (0)