Running astyle; Improved testing of std::find; std.cfg: Added support for istream::read and ifstream::read.

This commit is contained in:
orbitcowboy 2016-08-25 19:17:07 +02:00
parent b5085db3c8
commit 87409ea6b3
7 changed files with 68 additions and 16 deletions

View File

@ -3989,6 +3989,18 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<not-uninit/> <not-uninit/>
</arg> </arg>
</function> </function>
<!-- istream& read (char* s, streamsize n);
ifstream& read (char* s, streamsize n); -->
<function name="std::istream::read,std::ifstream::read">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<not-null/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
</function>
<!-- Not part of standard, but widely supported by runtime libraries. --> <!-- Not part of standard, but widely supported by runtime libraries. -->
<!-- char * itoa (int value, char * str, int base); --> <!-- char * itoa (int value, char * str, int base); -->
<function name="itoa"> <function name="itoa">
@ -4215,6 +4227,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<podtype name="mbstate_t"/> <podtype name="mbstate_t"/>
<podtype name="wint_t"/> <podtype name="wint_t"/>
<podtype name="jmp_buf"/> <podtype name="jmp_buf"/>
<podtype name="std::streamsize,streamsize" sign="s"/>
<!-- Fixed width integer sizes, defined in header <stdint.h> --> <!-- Fixed width integer sizes, defined in header <stdint.h> -->
<define name="INT8_MIN" value="-128"/> <define name="INT8_MIN" value="-128"/>
<define name="INT16_MIN" value="-32768"/> <define name="INT16_MIN" value="-32768"/>

View File

@ -40,7 +40,7 @@ static const CWE CWE664(664U); // Improper Control of a Resource Through its Li
static const CWE CWE685(685U); // Function Call With Incorrect Number of Arguments static const CWE CWE685(685U); // Function Call With Incorrect Number of Arguments
static const CWE CWE686(686U); // Function Call With Incorrect Argument Type static const CWE CWE686(686U); // Function Call With Incorrect Argument Type
static const CWE CWE687(687U); // Function Call With Incorrectly Specified Argument Value static const CWE CWE687(687U); // Function Call With Incorrectly Specified Argument Value
static const CWE CWE704(704U); // Incorrect Type Conversion or Cast static const CWE CWE704(704U); // Incorrect Type Conversion or Cast
static const CWE CWE910(910U); // Use of Expired File Descriptor static const CWE CWE910(910U); // Use of Expired File Descriptor
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -39,10 +39,10 @@ namespace {
} }
// CWE ID used: // CWE ID used:
static const CWE CWE398(398U); // Indicator of Poor Code Quality static const CWE CWE398(398U); // Indicator of Poor Code Quality
static const CWE CWE401(401U); // Improper Release of Memory Before Removing Last Reference ('Memory Leak') static const CWE CWE401(401U); // Improper Release of Memory Before Removing Last Reference ('Memory Leak')
static const CWE CWE771(771U); // Missing Reference to Active Allocated Resource static const CWE CWE771(771U); // Missing Reference to Active Allocated Resource
static const CWE CWE772(772U); // Missing Release of Resource after Effective Lifetime static const CWE CWE772(772U); // Missing Release of Resource after Effective Lifetime
/** /**
* Count function parameters * Count function parameters

View File

@ -30,7 +30,7 @@ namespace {
CheckNullPointer instance; CheckNullPointer instance;
} }
static const CWE CWE476(476U); // NULL Pointer Dereference static const CWE CWE476(476U); // NULL Pointer Dereference
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -36,8 +36,8 @@ namespace {
static const struct CWE CWE128(128U); // Wrap-around Error static const struct CWE CWE128(128U); // Wrap-around Error
static const struct CWE CWE131(131U); // Incorrect Calculation of Buffer Size static const struct CWE CWE131(131U); // Incorrect Calculation of Buffer Size
static const struct CWE CWE197(197U); // Numeric Truncation Error static const struct CWE CWE197(197U); // Numeric Truncation Error
static const struct CWE CWE362(362U); // Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') static const struct CWE CWE362(362U); // Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
static const struct CWE CWE369(369U); // Divide By Zero static const struct CWE CWE369(369U); // Divide By Zero
static const struct CWE CWE398(398U); // Indicator of Poor Code Quality static const struct CWE CWE398(398U); // Indicator of Poor Code Quality
static const struct CWE CWE475(475U); // Undefined Behavior for Input to API static const struct CWE CWE475(475U); // Undefined Behavior for Input to API
static const struct CWE CWE482(482U); // Comparing instead of Assigning static const struct CWE CWE482(482U); // Comparing instead of Assigning
@ -50,7 +50,7 @@ static const struct CWE CWE687(687U); // Function Call With Incorrectly Specif
static const struct CWE CWE688(688U); // Function Call With Incorrect Variable or Reference as Argument static const struct CWE CWE688(688U); // Function Call With Incorrect Variable or Reference as Argument
static const struct CWE CWE704(704U); // Incorrect Type Conversion or Cast static const struct CWE CWE704(704U); // Incorrect Type Conversion or Cast
static const struct CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior static const struct CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
static const struct CWE CWE768(768U); // Incorrect Short Circuit Evaluation static const struct CWE CWE768(768U); // Incorrect Short Circuit Evaluation
static const struct CWE CWE783(783U); // Operator Precedence Logic Error static const struct CWE CWE783(783U); // Operator Precedence Logic Error
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

View File

@ -1254,7 +1254,7 @@ void CheckStl::autoPointerError(const Token *tok)
reportError(tok, Severity::style, "useAutoPointerCopy", reportError(tok, Severity::style, "useAutoPointerCopy",
"Copying 'auto_ptr' pointer to another does not create two equal objects since one has lost its ownership of the pointer.\n" "Copying 'auto_ptr' pointer to another does not create two equal objects since one has lost its ownership of the pointer.\n"
"'std::auto_ptr' has semantics of strict ownership, meaning that the 'auto_ptr' instance is the sole entity responsible for the object's lifetime. If an 'auto_ptr' is copied, the source looses the reference.", "'std::auto_ptr' has semantics of strict ownership, meaning that the 'auto_ptr' instance is the sole entity responsible for the object's lifetime. If an 'auto_ptr' is copied, the source looses the reference.",
CWE398, false); CWE398, false);
} }
void CheckStl::autoPointerContainerError(const Token *tok) void CheckStl::autoPointerContainerError(const Token *tok)

View File

@ -23,6 +23,8 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <cinttypes> #include <cinttypes>
#include <istream>
#include <fstream>
void bufferAccessOutOfBounds(void) void bufferAccessOutOfBounds(void)
{ {
@ -2984,17 +2986,42 @@ void uninitvar_find(std::string s)
(void)s.find(pc,0); (void)s.find(pc,0);
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
(void)s.find(pc,pos); (void)s.find(pc,pos);
// cppcheck-suppress uninitvar
(void)s.find("test",pos);
// testing of size_t find (char c, size_t pos = 0) const; // testing of size_t find (char c, size_t pos = 0) const;
char c; char c;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
(void)s.find(c,pos); (void)s.find(c,pos);
/*
// testing of size_t find (const char* pc, size_t pos, size_t n) const; // testing of size_t find (const char* pc, size_t pos, size_t n) const;
size_t n; size_t n;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
(void)s.find(pc,pos,n); // #6991 (void)s.find(pc,pos,n); // #6991
*/ // cppcheck-suppress uninitvar
(void)s.find("test",pos,n);
// cppcheck-suppress uninitvar
(void)s.find("test",1,n);
// cppcheck-suppress uninitvar
(void)s.find("test",pos,1);
// cppcheck-suppress uninitvar
(void)s.find(pc,1,1);
}
void uninivar_ifstream_read(std::ifstream &f)
{
int size;
char buffer[10];
// cppcheck-suppress uninitvar
f.read(buffer, size);
}
void uninivar_istream_read(std::istream &f)
{
int size;
char buffer[10];
// cppcheck-suppress uninitvar
f.read(buffer, size);
} }
void invalidFunctionArgBool_abs(bool b, double x, double y) void invalidFunctionArgBool_abs(bool b, double x, double y)
@ -3015,6 +3042,18 @@ void ignoredReturnValue_abs(int i)
std::abs(-199); std::abs(-199);
} }
void nullPointer_ifstream_read(std::ifstream &f)
{
// cppcheck-suppress nullPointer
f.read(NULL, 10);
}
void nullPointer_istream_read(std::istream &f)
{
// cppcheck-suppress nullPointer
f.read(NULL, 10);
}
void nullPointer_asctime(void) void nullPointer_asctime(void)
{ {
struct tm *tm = 0; struct tm *tm = 0;