Cppcheck
Functions | Variables
checkbufferoverrun.cpp File Reference
#include "checkbufferoverrun.h"
#include "astutils.h"
#include "errorlogger.h"
#include "library.h"
#include "mathlib.h"
#include "platform.h"
#include "settings.h"
#include "symboldatabase.h"
#include "token.h"
#include "tokenize.h"
#include "utils.h"
#include "valueflow.h"
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iterator>
#include <numeric>
#include <sstream>
#include <utility>
#include "xml.h"

Go to the source code of this file.

Functions

static const ValueFlow::ValuegetBufferSizeValue (const Token *tok)
 
static int getMinFormatStringOutputLength (const std::vector< const Token * > &parameters, nonneg int formatStringArgNr)
 
static bool getDimensionsEtc (const Token *const arrayToken, const Settings *settings, std::vector< Dimension > &dimensions, ErrorPath &errorPath, bool &mightBeLarger, MathLib::bigint &path)
 
static ValueFlow::Value makeSizeValue (MathLib::bigint size, MathLib::bigint path)
 
static std::vector< ValueFlow::ValuegetOverrunIndexValues (const Token *tok, const Token *arrayToken, const std::vector< Dimension > &dimensions, const std::vector< const Token * > &indexTokens, MathLib::bigint path)
 
static std::string stringifyIndexes (const std::string &array, const std::vector< ValueFlow::Value > &indexValues)
 
static std::string arrayIndexMessage (const Token *tok, const std::vector< Dimension > &dimensions, const std::vector< ValueFlow::Value > &indexValues, const Token *condition)
 
static bool checkBufferSize (const Token *ftok, const Library::ArgumentChecks::MinSize &minsize, const std::vector< const Token * > &args, const MathLib::bigint bufferSize, const Settings *settings, const Tokenizer *tokenizer)
 
static bool isVLAIndex (const Token *tok)
 

Variables

static const CWE CWE131 (131U)
 
static const CWE CWE170 (170U)
 
static const CWE CWE_ARGUMENT_SIZE (398U)
 
static const CWE CWE_ARRAY_INDEX_THEN_CHECK (398U)
 
static const CWE CWE758 (758U)
 
static const CWE CWE_POINTER_ARITHMETIC_OVERFLOW (758U)
 
static const CWE CWE_BUFFER_UNDERRUN (786U)
 
static const CWE CWE_BUFFER_OVERRUN (788U)
 

Function Documentation

◆ arrayIndexMessage()

static std::string arrayIndexMessage ( const Token tok,
const std::vector< Dimension > &  dimensions,
const std::vector< ValueFlow::Value > &  indexValues,
const Token condition 
)
static

◆ checkBufferSize()

static bool checkBufferSize ( const Token ftok,
const Library::ArgumentChecks::MinSize minsize,
const std::vector< const Token * > &  args,
const MathLib::bigint  bufferSize,
const Settings settings,
const Tokenizer tokenizer 
)
static

◆ getBufferSizeValue()

static const ValueFlow::Value* getBufferSizeValue ( const Token tok)
static

◆ getDimensionsEtc()

static bool getDimensionsEtc ( const Token *const  arrayToken,
const Settings settings,
std::vector< Dimension > &  dimensions,
ErrorPath errorPath,
bool &  mightBeLarger,
MathLib::bigint path 
)
static

◆ getMinFormatStringOutputLength()

static int getMinFormatStringOutputLength ( const std::vector< const Token * > &  parameters,
nonneg int  formatStringArgNr 
)
static

Definition at line 75 of file checkbufferoverrun.cpp.

References Token::eString, and Token::getStrLength().

Referenced by checkBufferSize().

◆ getOverrunIndexValues()

static std::vector<ValueFlow::Value> getOverrunIndexValues ( const Token tok,
const Token arrayToken,
const std::vector< Dimension > &  dimensions,
const std::vector< const Token * > &  indexTokens,
MathLib::bigint  path 
)
static

◆ isVLAIndex()

static bool isVLAIndex ( const Token tok)
static

◆ makeSizeValue()

static ValueFlow::Value makeSizeValue ( MathLib::bigint  size,
MathLib::bigint  path 
)
static

◆ stringifyIndexes()

static std::string stringifyIndexes ( const std::string &  array,
const std::vector< ValueFlow::Value > &  indexValues 
)
static

Definition at line 366 of file checkbufferoverrun.cpp.

Referenced by arrayIndexMessage().

Variable Documentation

◆ CWE131

const CWE CWE131(131U) ( 131U  )
static

◆ CWE170

const CWE CWE170(170U) ( 170U  )
static

◆ CWE758

const CWE CWE758(758U) ( 758U  )
static

◆ CWE_ARGUMENT_SIZE

const CWE CWE_ARGUMENT_SIZE(398U) ( 398U  )
static

◆ CWE_ARRAY_INDEX_THEN_CHECK

const CWE CWE_ARRAY_INDEX_THEN_CHECK(398U) ( 398U  )
static

◆ CWE_BUFFER_OVERRUN

const CWE CWE_BUFFER_OVERRUN(788U) ( 788U  )
static

◆ CWE_BUFFER_UNDERRUN

const CWE CWE_BUFFER_UNDERRUN(786U) ( 786U  )
static

◆ CWE_POINTER_ARITHMETIC_OVERFLOW

const CWE CWE_POINTER_ARITHMETIC_OVERFLOW(758U) ( 758U  )
static