checkio: Fixed potential usage of invalid iterator. (#1066)
* checkio: Fixed potential usage of invalid iterator. * formatted the code. A ticket about FN (invalidIterator1) is created at https://trac.cppcheck.net/ticket/8373
This commit is contained in:
parent
4b5e4f989a
commit
f5e6ef9fd2
|
@ -1226,14 +1226,15 @@ void CheckIO::checkFormatString(const Token * const tok,
|
|||
done = true;
|
||||
break;
|
||||
case 'h': // Can be 'hh' (signed char or unsigned char) or 'h' (short int or unsigned short int)
|
||||
case 'l': // Can be 'll' (long long int or unsigned long long int) or 'l' (long int or unsigned long int)
|
||||
case 'l': { // Can be 'll' (long long int or unsigned long long int) or 'l' (long int or unsigned long int)
|
||||
// If the next character is the same (which makes 'hh' or 'll') then expect another alphabetical character
|
||||
if (i != formatString.end() && *(i+1) == *i) {
|
||||
if (i+1 != formatString.end()) {
|
||||
if (!isalpha(*(i+2))) {
|
||||
const bool isSecondCharAvailable = ((i + 1) != formatString.end());
|
||||
if (i != formatString.end() && isSecondCharAvailable && *(i + 1) == *i) {
|
||||
if (isSecondCharAvailable) {
|
||||
if (!isalpha(*(i + 2))) {
|
||||
std::string modifier;
|
||||
modifier += *i;
|
||||
modifier += *(i+1);
|
||||
modifier += *(i + 1);
|
||||
invalidLengthModifierError(tok, numFormat, modifier);
|
||||
done = true;
|
||||
} else {
|
||||
|
@ -1245,7 +1246,7 @@ void CheckIO::checkFormatString(const Token * const tok,
|
|||
}
|
||||
} else {
|
||||
if (i != formatString.end()) {
|
||||
if (!isalpha(*(i+1))) {
|
||||
if ((i + 1) != formatString.end() && !isalpha(*(i + 1))) {
|
||||
std::string modifier;
|
||||
modifier += *i;
|
||||
invalidLengthModifierError(tok, numFormat, modifier);
|
||||
|
@ -1257,6 +1258,7 @@ void CheckIO::checkFormatString(const Token * const tok,
|
|||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'I': // Microsoft extension: I for size_t and ptrdiff_t, I32 for __int32, and I64 for __int64
|
||||
if ((*(i+1) == '3' && *(i+2) == '2') ||
|
||||
|
|
|
@ -92,7 +92,8 @@ void memleak_mmap(int fd)
|
|||
// cppcheck-suppress memleak
|
||||
}
|
||||
|
||||
void resourceLeak_fdopen(int fd) {
|
||||
void resourceLeak_fdopen(int fd)
|
||||
{
|
||||
// cppcheck-suppress unreadVariable
|
||||
FILE *f = fdopen(fd, "r");
|
||||
// cppcheck-suppress resourceLeak
|
||||
|
|
Loading…
Reference in New Issue