borland and visual c++ fixes

This commit is contained in:
Daniel Marjamäki 2009-01-23 21:28:45 +00:00
parent d9b9368238
commit 42e56153a4
8 changed files with 3371 additions and 3369 deletions

View File

@ -1,4 +1,4 @@
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
* Leandro Penz, Kimmo Varis * Leandro Penz, Kimmo Varis
@ -92,7 +92,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
if (Token::Match(tok, "%varid% [ %num% ]", varid)) if (Token::Match(tok, "%varid% [ %num% ]", varid))
{ {
const char *num = tok->strAt(2); const char *num = tok->strAt(2);
if (strtol(num, NULL, 10) >= size) if (std::strtol(num, NULL, 10) >= size)
{ {
ReportError(ErrorMessage::arrayIndexOutOfBounds(_tokenizer, tok->next())); ReportError(ErrorMessage::arrayIndexOutOfBounds(_tokenizer, tok->next()));
} }
@ -101,7 +101,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
else if (Token::Match(tok, std::string(varnames + " [ %num% ]").c_str())) else if (Token::Match(tok, std::string(varnames + " [ %num% ]").c_str()))
{ {
const char *num = tok->strAt(2 + varc); const char *num = tok->strAt(2 + varc);
if (strtol(num, NULL, 10) >= size) if (std::strtol(num, NULL, 10) >= size)
{ {
ReportError(ErrorMessage::arrayIndexOutOfBounds(_tokenizer, tok->next())); ReportError(ErrorMessage::arrayIndexOutOfBounds(_tokenizer, tok->next()));
} }
@ -129,7 +129,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
if (!tok->isName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), "%varid% [ %num% ]", varid)) if (!tok->isName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), "%varid% [ %num% ]", varid))
{ {
const char *num = tok->strAt(3); const char *num = tok->strAt(3);
if (strtol(num, NULL, 10) >= size) if (std::strtol(num, NULL, 10) >= size)
{ {
ReportError(ErrorMessage::arrayIndexOutOfBounds(_tokenizer, tok->next())); ReportError(ErrorMessage::arrayIndexOutOfBounds(_tokenizer, tok->next()));
} }
@ -138,7 +138,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
else if (!tok->isName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), std::string(varnames + " [ %num% ]").c_str())) else if (!tok->isName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), std::string(varnames + " [ %num% ]").c_str()))
{ {
const char *num = tok->next()->strAt(2 + varc); const char *num = tok->next()->strAt(2 + varc);
if (strtol(num, NULL, 10) >= size) if (std::strtol(num, NULL, 10) >= size)
{ {
ReportError(ErrorMessage::arrayIndexOutOfBounds(_tokenizer, tok->next())); ReportError(ErrorMessage::arrayIndexOutOfBounds(_tokenizer, tok->next()));
} }
@ -156,7 +156,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
Token::Match(tok->next(), "( %var% , %varid% , %num% )", varid)) Token::Match(tok->next(), "( %var% , %varid% , %num% )", varid))
{ {
const char *num = tok->strAt(6); const char *num = tok->strAt(6);
if (atoi(num) > total_size) if (std::atoi(num) > total_size)
{ {
ReportError(ErrorMessage::bufferOverrun(_tokenizer, tok)); ReportError(ErrorMessage::bufferOverrun(_tokenizer, tok));
} }
@ -170,7 +170,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
Token::Match(tok->next(), std::string("( %var% , " + varnames + " , %num% )").c_str())) Token::Match(tok->next(), std::string("( %var% , " + varnames + " , %num% )").c_str()))
{ {
const char *num = tok->strAt(varc + 6); const char *num = tok->strAt(varc + 6);
if (atoi(num) > total_size) if (std::atoi(num) > total_size)
{ {
ReportError(ErrorMessage::bufferOverrun(_tokenizer, tok)); ReportError(ErrorMessage::bufferOverrun(_tokenizer, tok));
} }
@ -200,7 +200,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
// Get index variable and stopsize. // Get index variable and stopsize.
const char *strindex = tok2->aaaa(); const char *strindex = tok2->aaaa();
int value = ((tok2->next()->aaaa1() == '=') ? 1 : 0) + atoi(tok2->strAt(2)); int value = ((tok2->next()->aaaa1() == '=') ? 1 : 0) + std::atoi(tok2->strAt(2));
if (value <= size) if (value <= size)
continue; continue;
@ -287,7 +287,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
// snprintf.. // snprintf..
if (varid > 0 && Token::Match(tok, "snprintf ( %varid% , %num%", varid)) if (varid > 0 && Token::Match(tok, "snprintf ( %varid% , %num%", varid))
{ {
int n = atoi(tok->strAt(4)); int n = std::atoi(tok->strAt(4));
if (n > size) if (n > size)
ReportError(ErrorMessage::outOfBounds(_tokenizer, tok->tokAt(4), "snprintf size")); ReportError(ErrorMessage::outOfBounds(_tokenizer, tok->tokAt(4), "snprintf size"));
} }
@ -412,7 +412,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_LocalVariable()
if (Token::Match(tok, "%type% %var% [ %num% ] ;")) if (Token::Match(tok, "%type% %var% [ %num% ] ;"))
{ {
varname[0] = tok->strAt(1); varname[0] = tok->strAt(1);
size = strtoul(tok->strAt(3), NULL, 10); size = std::strtoul(tok->strAt(3), NULL, 10);
type = tok->aaaa(); type = tok->aaaa();
varid = tok->tokAt(1)->varId(); varid = tok->tokAt(1)->varId();
nextTok = 6; nextTok = 6;
@ -420,7 +420,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_LocalVariable()
else if (Token::Match(tok, "[*;{}] %var% = new %type% [ %num% ]")) else if (Token::Match(tok, "[*;{}] %var% = new %type% [ %num% ]"))
{ {
varname[0] = tok->strAt(1); varname[0] = tok->strAt(1);
size = strtoul(tok->strAt(6), NULL, 10); size = std::strtoul(tok->strAt(6), NULL, 10);
type = tok->strAt(4); type = tok->strAt(4);
varid = tok->tokAt(1)->varId(); varid = tok->tokAt(1)->varId();
nextTok = 8; nextTok = 8;
@ -475,7 +475,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
const char *varname[3] = {0, 0, 0}; const char *varname[3] = {0, 0, 0};
varname[1] = tok2->strAt(ivar); varname[1] = tok2->strAt(ivar);
int arrsize = atoi(tok2->strAt(ivar + 2)); int arrsize = std::atoi(tok2->strAt(ivar + 2));
int total_size = arrsize * _tokenizer->SizeOfType(tok2->next()->aaaa()); int total_size = arrsize * _tokenizer->SizeOfType(tok2->next()->aaaa());
if (total_size == 0) if (total_size == 0)
continue; continue;

View File

@ -1,4 +1,4 @@
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
* Leandro Penz, Kimmo Varis * Leandro Penz, Kimmo Varis

View File

@ -1,4 +1,4 @@
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
* Leandro Penz, Kimmo Varis * Leandro Penz, Kimmo Varis
@ -316,7 +316,7 @@ void CheckOther::InvalidFunctionUsage()
{ {
if (Token::Match(tok2, ", %num% )")) if (Token::Match(tok2, ", %num% )"))
{ {
int radix = atoi(tok2->strAt(1)); int radix = std::atoi(tok2->strAt(1));
if (!(radix == 0 || (radix >= 2 && radix <= 36))) if (!(radix == 0 || (radix >= 2 && radix <= 36)))
{ {
_errorLogger->reportErr(ErrorMessage::dangerousUsageStrtol(_tokenizer, tok2)); _errorLogger->reportErr(ErrorMessage::dangerousUsageStrtol(_tokenizer, tok2));

View File

@ -1,4 +1,4 @@
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
* Leandro Penz, Kimmo Varis * Leandro Penz, Kimmo Varis

View File

@ -1,4 +1,4 @@
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
* Leandro Penz, Kimmo Varis * Leandro Penz, Kimmo Varis
@ -27,6 +27,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <cctype>
Preprocessor::Preprocessor() Preprocessor::Preprocessor()
{ {
@ -72,7 +73,7 @@ std::string Preprocessor::read(std::istream &istr)
++lineno; ++lineno;
// Replace assorted special chars with spaces.. // Replace assorted special chars with spaces..
if ((ch != '\n') && (isspace(ch) || iscntrl(ch))) if ((ch != '\n') && (std::isspace(ch) || std::iscntrl(ch)))
ch = ' '; ch = ' ';
// Skip spaces after ' ' and after '#' // Skip spaces after ' ' and after '#'
@ -697,7 +698,7 @@ std::string Preprocessor::expandMacros(std::string code)
std::string::size_type pos = pos1 + macro.name().length(); std::string::size_type pos = pos1 + macro.name().length();
if (pos < code.length() if (pos < code.length()
&& code.substr(pos1, macro.name().length()) == macro.name() && code.substr(pos1, macro.name().length()) == macro.name()
&& !isalnum(code[pos]) && code[pos] != '_') && !std::isalnum(code[pos]) && code[pos] != '_')
break; break;
@ -720,7 +721,7 @@ std::string Preprocessor::expandMacros(std::string code)
// TODO, this code is here, because there is currently a bug in cppcheck // TODO, this code is here, because there is currently a bug in cppcheck
// Once it has been sorted out, this if can be removed // Once it has been sorted out, this if can be removed
std::cout << "\n\n####### There is a bug in preprocessor.cpp that can cause crash, shutting down.\n\n" << std::endl; std::cout << "\n\n####### There is a bug in preprocessor.cpp that can cause crash, shutting down.\n\n" << std::endl;
exit(0); std::exit(0);
} }
} }
continue; continue;
@ -732,14 +733,14 @@ std::string Preprocessor::expandMacros(std::string code)
continue; continue;
// Previous char must not be alphanumeric or '_' // Previous char must not be alphanumeric or '_'
if (pos1 != 0 && (isalnum(code[pos1-1]) || code[pos1-1] == '_')) if (pos1 != 0 && (std::isalnum(code[pos1-1]) || code[pos1-1] == '_'))
continue; continue;
// The char after the macroname must not be alphanumeric or '_' // The char after the macroname must not be alphanumeric or '_'
if (pos1 + macro.name().length() < code.length()) if (pos1 + macro.name().length() < code.length())
{ {
std::string::size_type pos2 = pos1 + macro.name().length(); std::string::size_type pos2 = pos1 + macro.name().length();
if (isalnum(code[pos2]) || code[pos2] == '_') if (std::isalnum(code[pos2]) || code[pos2] == '_')
continue; continue;
} }

View File

@ -1,4 +1,4 @@
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
* Leandro Penz, Kimmo Varis * Leandro Penz, Kimmo Varis

View File

@ -1,4 +1,4 @@
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
* Leandro Penz, Kimmo Varis * Leandro Penz, Kimmo Varis
@ -31,6 +31,7 @@
#include <list> #include <list>
#include <algorithm> #include <algorithm>
#include <cstdlib> #include <cstdlib>
#include <cctype>
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -79,7 +80,7 @@ void Tokenizer::addtoken(const char str[], const unsigned int lineno, const unsi
std::ostringstream str2; std::ostringstream str2;
if (strncmp(str, "0x", 2) == 0) if (strncmp(str, "0x", 2) == 0)
{ {
str2 << strtoul(str + 2, NULL, 16); str2 << std::strtoul(str + 2, NULL, 16);
} }
else else
{ {
@ -332,7 +333,7 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[])
} }
if (isspace(ch) || iscntrl(ch)) if (std::isspace(ch) || std::iscntrl(ch))
{ {
addtoken(CurrentToken.c_str(), lineno, FileIndex); addtoken(CurrentToken.c_str(), lineno, FileIndex);
CurrentToken.clear(); CurrentToken.clear();
@ -651,7 +652,7 @@ void Tokenizer::simplifyTokenList()
continue; continue;
const char *varname = tok->strAt(1); const char *varname = tok->strAt(1);
int total_size = size * atoi(tok->strAt(3)); int total_size = size * std::atoi(tok->strAt(3));
// Replace 'sizeof(var)' with number // Replace 'sizeof(var)' with number
int indentlevel = 0; int indentlevel = 0;
@ -705,8 +706,8 @@ void Tokenizer::simplifyTokenList()
// (1-2) // (1-2)
if (Token::Match(tok, "[[,(=<>] %num% [+-*/] %num% [],);=<>]")) if (Token::Match(tok, "[[,(=<>] %num% [+-*/] %num% [],);=<>]"))
{ {
int i1 = atoi(tok->strAt(1)); int i1 = std::atoi(tok->strAt(1));
int i2 = atoi(tok->strAt(3)); int i2 = std::atoi(tok->strAt(3));
if (i2 == 0 && *(tok->strAt(2)) == '/') if (i2 == 0 && *(tok->strAt(2)) == '/')
{ {
continue; continue;
@ -1201,8 +1202,8 @@ bool Tokenizer::simplifyConditions()
Token::Match(tok->tokAt(1), "%num% %any% %num%") && Token::Match(tok->tokAt(1), "%num% %any% %num%") &&
(tok4->str() == "&&" || tok4->str() == "||" || tok4->str() == ")")) (tok4->str() == "&&" || tok4->str() == "||" || tok4->str() == ")"))
{ {
double op1 = (strstr(tok->strAt(1), "0x")) ? strtol(tok->strAt(1), 0, 16) : atof(tok->strAt(1)); double op1 = (strstr(tok->strAt(1), "0x")) ? std::strtol(tok->strAt(1), 0, 16) : std::atof(tok->strAt(1));
double op2 = (strstr(tok->strAt(3), "0x")) ? strtol(tok->strAt(3), 0, 16) : atof(tok->strAt(3)); double op2 = (strstr(tok->strAt(3), "0x")) ? std::strtol(tok->strAt(3), 0, 16) : std::atof(tok->strAt(3));
std::string cmp = tok->strAt(2); std::string cmp = tok->strAt(2);
bool result = false; bool result = false;

View File

@ -1,4 +1,4 @@
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
* Leandro Penz, Kimmo Varis * Leandro Penz, Kimmo Varis