From 6b8cb08ec681dfbbfc23e92aa8f87a7c7172d991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 18 Feb 2010 22:25:29 +0100 Subject: [PATCH] Refactoring CheckBufferOverrun. Use std::string instead of const char * --- lib/checkbufferoverrun.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 3cf8221a9..62348bcff 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -171,7 +171,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstrAt(2 + varc)); if (index < 0 || index >= size) @@ -216,7 +216,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorisName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), std::string(varnames + " [ %num% ]").c_str())) + else if (!tok->isName() && !Token::Match(tok, "[.&]") && Token::Match(tok->next(), (varnames + " [ %num% ]").c_str())) { int index = MathLib::toLongNumber(tok->strAt(3 + varc)); if (index < 0 || index >= size) @@ -280,8 +280,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectornext(), std::string("( " + varnames + " , %num% , %num% )").c_str()) || - Token::Match(tok->next(), std::string("( %var% , " + varnames + " , %num% )").c_str())) + if (Token::Match(tok->next(), ("( " + varnames + " , %num% , %num% )").c_str()) || + Token::Match(tok->next(), ("( %var% , " + varnames + " , %num% )").c_str())) { const std::string num = tok->strAt(varc + 6); if (MathLib::toLongNumber(num) < 0 || MathLib::toLongNumber(num) > total_size) @@ -357,14 +357,14 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector(value + 1); - value = MathLib::toLongNumber(max_counter_value.c_str()); + value = MathLib::toLongNumber(max_counter_value); strindextoken = tok2->tokAt(2); } else if (Token::Match(tok2, "%num% <= %varid% ;", counter_varid)) { max_counter_value = min_counter_value; min_counter_value = tok2->str(); - value = MathLib::toLongNumber(max_counter_value.c_str()); + value = MathLib::toLongNumber(max_counter_value); strindextoken = tok2->tokAt(2); } else @@ -373,7 +373,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorstr().c_str(); + const std::string strindex = strindextoken->str(); bool condition_out_of_bounds = true; if (value <= size) condition_out_of_bounds = false; @@ -677,13 +677,13 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector 0 && Token::Match(tok2, std::string("[(,] %varid% [,)]").c_str(), varid)) + if (varid > 0 && Token::Match(tok2, "[(,] %varid% [,)]", varid)) { ++par; tok1 = tok2->next(); break; } - else if (varid == 0 && Token::Match(tok2, std::string("[(,] " + varnames + " [,)]").c_str())) + else if (varid == 0 && Token::Match(tok2, ("[(,] " + varnames + " [,)]").c_str())) { ++par; tok1 = tok2->tokAt(varc + 1);