std.cfg: Improved configuration of qsort().

This commit is contained in:
orbitcowboy 2022-05-02 11:58:31 +02:00
parent 6a657865eb
commit 0ec2d5f40d
3 changed files with 27 additions and 0 deletions

View File

@ -4340,6 +4340,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<arg nr="1" direction="inout"> <arg nr="1" direction="inout">
<not-null/> <not-null/>
<not-uninit/> <not-uninit/>
<minsize type="argvalue" arg="2"/>
</arg> </arg>
<arg nr="2" direction="in"> <arg nr="2" direction="in">
<not-uninit/> <not-uninit/>
@ -4352,6 +4353,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<arg nr="4" direction="in"> <arg nr="4" direction="in">
<not-null/> <not-null/>
<not-uninit/> <not-uninit/>
<not-bool/>
</arg> </arg>
</function> </function>
<!-- int putc(int c, FILE *stream); --> <!-- int putc(int c, FILE *stream); -->

View File

@ -26,6 +26,19 @@
#include <inttypes.h> #include <inttypes.h>
#include <float.h> #include <float.h>
int qsort_cmpfunc (const void * a, const void * b) {
return (*(int*)a - *(int*)b);
}
void nullPointer_qsort(void *base, size_t n, size_t size, int (*cmp)(const void *, const void *))
{
// cppcheck-suppress nullPointer
qsort(NULL, n, size, qsort_cmpfunc);
// cppcheck-suppress nullPointer
qsort(base, n, size, NULL);
qsort(base, n, size, qsort_cmpfunc);
}
// As with all bounds-checked functions, localtime_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including time.h. // As with all bounds-checked functions, localtime_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including time.h.
#ifdef __STDC_LIB_EXT1__ #ifdef __STDC_LIB_EXT1__
void uninitvar_localtime_s(const time_t *restrict time, struct tm *restrict result) void uninitvar_localtime_s(const time_t *restrict time, struct tm *restrict result)

View File

@ -32,6 +32,18 @@
#include <iterator> #include <iterator>
#include <vector> #include <vector>
int qsort_cmpfunc (const void * a, const void * b) {
return (*static_cast<const int*>(a) - *static_cast<const int*>(b));
}
void nullPointer_qsort(void *base, std::size_t n, std::size_t size, int (*cmp)(const void *, const void *))
{
// cppcheck-suppress nullPointer
std::qsort(nullptr, n, size, qsort_cmpfunc);
// cppcheck-suppress nullPointer
std::qsort(base, n, size, nullptr);
std::qsort(base, n, size, qsort_cmpfunc);
}
void *bufferAccessOutOfBounds_memchr(void *s, int c, size_t n) void *bufferAccessOutOfBounds_memchr(void *s, int c, size_t n)
{ {
char buf[42]={0}; char buf[42]={0};