Skip to content

Commit 87409ea

Browse files
committed
Running astyle; Improved testing of std::find; std.cfg: Added support for istream::read and ifstream::read.
1 parent b5085db commit 87409ea

File tree

7 files changed

+68
-16
lines changed

7 files changed

+68
-16
lines changed

cfg/std.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3989,6 +3989,18 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
39893989
<not-uninit/>
39903990
</arg>
39913991
</function>
3992+
<!-- istream& read (char* s, streamsize n);
3993+
ifstream& read (char* s, streamsize n); -->
3994+
<function name="std::istream::read,std::ifstream::read">
3995+
<noreturn>false</noreturn>
3996+
<leak-ignore/>
3997+
<arg nr="1">
3998+
<not-null/>
3999+
</arg>
4000+
<arg nr="2">
4001+
<not-uninit/>
4002+
</arg>
4003+
</function>
39924004
<!-- Not part of standard, but widely supported by runtime libraries. -->
39934005
<!-- char * itoa (int value, char * str, int base); -->
39944006
<function name="itoa">
@@ -4215,6 +4227,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
42154227
<podtype name="mbstate_t"/>
42164228
<podtype name="wint_t"/>
42174229
<podtype name="jmp_buf"/>
4230+
<podtype name="std::streamsize,streamsize" sign="s"/>
42184231
<!-- Fixed width integer sizes, defined in header <stdint.h> -->
42194232
<define name="INT8_MIN" value="-128"/>
42204233
<define name="INT16_MIN" value="-32768"/>

lib/checkio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static const CWE CWE664(664U); // Improper Control of a Resource Through its Li
4040
static const CWE CWE685(685U); // Function Call With Incorrect Number of Arguments
4141
static const CWE CWE686(686U); // Function Call With Incorrect Argument Type
4242
static const CWE CWE687(687U); // Function Call With Incorrectly Specified Argument Value
43-
static const CWE CWE704(704U); // Incorrect Type Conversion or Cast
43+
static const CWE CWE704(704U); // Incorrect Type Conversion or Cast
4444
static const CWE CWE910(910U); // Use of Expired File Descriptor
4545

4646
//---------------------------------------------------------------------------

lib/checkmemoryleak.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ namespace {
3939
}
4040

4141
// CWE ID used:
42-
static const CWE CWE398(398U); // Indicator of Poor Code Quality
43-
static const CWE CWE401(401U); // Improper Release of Memory Before Removing Last Reference ('Memory Leak')
44-
static const CWE CWE771(771U); // Missing Reference to Active Allocated Resource
45-
static const CWE CWE772(772U); // Missing Release of Resource after Effective Lifetime
42+
static const CWE CWE398(398U); // Indicator of Poor Code Quality
43+
static const CWE CWE401(401U); // Improper Release of Memory Before Removing Last Reference ('Memory Leak')
44+
static const CWE CWE771(771U); // Missing Reference to Active Allocated Resource
45+
static const CWE CWE772(772U); // Missing Release of Resource after Effective Lifetime
4646

4747
/**
4848
* Count function parameters

lib/checknullpointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace {
3030
CheckNullPointer instance;
3131
}
3232

33-
static const CWE CWE476(476U); // NULL Pointer Dereference
33+
static const CWE CWE476(476U); // NULL Pointer Dereference
3434

3535
//---------------------------------------------------------------------------
3636

lib/checkother.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace {
3636
static const struct CWE CWE128(128U); // Wrap-around Error
3737
static const struct CWE CWE131(131U); // Incorrect Calculation of Buffer Size
3838
static const struct CWE CWE197(197U); // Numeric Truncation Error
39-
static const struct CWE CWE362(362U); // Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
40-
static const struct CWE CWE369(369U); // Divide By Zero
39+
static const struct CWE CWE362(362U); // Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
40+
static const struct CWE CWE369(369U); // Divide By Zero
4141
static const struct CWE CWE398(398U); // Indicator of Poor Code Quality
4242
static const struct CWE CWE475(475U); // Undefined Behavior for Input to API
4343
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
5050
static const struct CWE CWE688(688U); // Function Call With Incorrect Variable or Reference as Argument
5151
static const struct CWE CWE704(704U); // Incorrect Type Conversion or Cast
5252
static const struct CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
53-
static const struct CWE CWE768(768U); // Incorrect Short Circuit Evaluation
53+
static const struct CWE CWE768(768U); // Incorrect Short Circuit Evaluation
5454
static const struct CWE CWE783(783U); // Operator Precedence Logic Error
5555

5656
//----------------------------------------------------------------------------------

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ void CheckStl::autoPointerError(const Token *tok)
12541254
reportError(tok, Severity::style, "useAutoPointerCopy",
12551255
"Copying 'auto_ptr' pointer to another does not create two equal objects since one has lost its ownership of the pointer.\n"
12561256
"'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.",
1257-
CWE398, false);
1257+
CWE398, false);
12581258
}
12591259

12601260
void CheckStl::autoPointerContainerError(const Token *tok)

test/cfg/std.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <iostream>
2424
#include <iomanip>
2525
#include <cinttypes>
26+
#include <istream>
27+
#include <fstream>
2628

2729
void bufferAccessOutOfBounds(void)
2830
{
@@ -2984,17 +2986,42 @@ void uninitvar_find(std::string s)
29842986
(void)s.find(pc,0);
29852987
// cppcheck-suppress uninitvar
29862988
(void)s.find(pc,pos);
2989+
// cppcheck-suppress uninitvar
2990+
(void)s.find("test",pos);
29872991

29882992
// testing of size_t find (char c, size_t pos = 0) const;
29892993
char c;
29902994
// cppcheck-suppress uninitvar
29912995
(void)s.find(c,pos);
2992-
/*
2993-
// testing of size_t find (const char* pc, size_t pos, size_t n) const;
2994-
size_t n;
2995-
// cppcheck-suppress uninitvar
2996-
(void)s.find(pc,pos,n); // #6991
2997-
*/
2996+
2997+
// testing of size_t find (const char* pc, size_t pos, size_t n) const;
2998+
size_t n;
2999+
// cppcheck-suppress uninitvar
3000+
(void)s.find(pc,pos,n); // #6991
3001+
// cppcheck-suppress uninitvar
3002+
(void)s.find("test",pos,n);
3003+
// cppcheck-suppress uninitvar
3004+
(void)s.find("test",1,n);
3005+
// cppcheck-suppress uninitvar
3006+
(void)s.find("test",pos,1);
3007+
// cppcheck-suppress uninitvar
3008+
(void)s.find(pc,1,1);
3009+
}
3010+
3011+
void uninivar_ifstream_read(std::ifstream &f)
3012+
{
3013+
int size;
3014+
char buffer[10];
3015+
// cppcheck-suppress uninitvar
3016+
f.read(buffer, size);
3017+
}
3018+
3019+
void uninivar_istream_read(std::istream &f)
3020+
{
3021+
int size;
3022+
char buffer[10];
3023+
// cppcheck-suppress uninitvar
3024+
f.read(buffer, size);
29983025
}
29993026

30003027
void invalidFunctionArgBool_abs(bool b, double x, double y)
@@ -3015,6 +3042,18 @@ void ignoredReturnValue_abs(int i)
30153042
std::abs(-199);
30163043
}
30173044

3045+
void nullPointer_ifstream_read(std::ifstream &f)
3046+
{
3047+
// cppcheck-suppress nullPointer
3048+
f.read(NULL, 10);
3049+
}
3050+
3051+
void nullPointer_istream_read(std::istream &f)
3052+
{
3053+
// cppcheck-suppress nullPointer
3054+
f.read(NULL, 10);
3055+
}
3056+
30183057
void nullPointer_asctime(void)
30193058
{
30203059
struct tm *tm = 0;

0 commit comments

Comments
 (0)