std.cfg: Ensure null pointer input is correctly handled for fgets() and fgetws().

This commit is contained in:
orbitcowboy 2022-04-20 08:50:45 +02:00
parent df84bed889
commit 5be16c3113
2 changed files with 40 additions and 0 deletions

View File

@ -85,6 +85,26 @@ void bufferAccessOutOfBounds(void)
free(pAlloc1); free(pAlloc1);
} }
wchar_t* nullPointer_fgetws(wchar_t* buffer, int n, FILE* stream)
{
// cppcheck-suppress nullPointer
(void)fgetws(NULL,n,stream);
// cppcheck-suppress nullPointer
(void)fgetws(buffer,n,NULL);
// No warning is expected
return fgetws(buffer, n, stream);
}
char* nullPointer_fgets(char *buffer, int n, FILE *stream)
{
// cppcheck-suppress nullPointer
(void)fgets(NULL,n,stream);
// cppcheck-suppress nullPointer
(void)fgets(buffer,n,NULL);
// No warning is expected
return fgets(buffer, n, stream);
}
void memleak_aligned_alloc(void) void memleak_aligned_alloc(void)
{ {
// cppcheck-suppress unusedAllocatedMemory // cppcheck-suppress unusedAllocatedMemory

View File

@ -1264,6 +1264,26 @@ void uninitvar_fsetpos(void)
(void)std::fsetpos(stream,ptr); (void)std::fsetpos(stream,ptr);
} }
wchar_t* nullPointer_fgetws(wchar_t* buffer, int n, FILE* stream)
{
// cppcheck-suppress nullPointer
(void)std::fgetws(NULL,n,stream);
// cppcheck-suppress nullPointer
(void)std::fgetws(buffer,n,NULL);
// No warning is expected
return std::fgetws(buffer, n, stream);
}
char* nullPointer_fgets(char *buffer, int n, FILE *stream)
{
// cppcheck-suppress nullPointer
(void)std::fgets(NULL,n,stream);
// cppcheck-suppress nullPointer
(void)std::fgets(buffer,n,NULL);
// No warning is expected
return std::fgets(buffer, n, stream);
}
void uninitvar_fgets(void) void uninitvar_fgets(void)
{ {
char *buffer; char *buffer;