Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ffcccc
langcpp

enum { TABLESIZE = 100 };

int *table = NULL;

int insert_in_table(int pos, int value){
  if (!table) {
    table = new int[TABLESIZE];
  }
  if (pos >= TABLESIZE) {
    return -1;
  }
  table[pos] = value;
  return 0;
}

...

Code Block
bgColor#ccccff
langcpp

enum { TABLESIZE = 100 };

int *table = NULL;

int insert_in_table(size_t pos, int value){
  if (!table) {
    table = new int[TABLESIZE];
  }
  if (pos >= TABLESIZE) {
    return -1;
  }
  table[pos] = value;
  return 0;
}

...

Code Block
bgColor#ccccff
langcpp

template <typename T>
void clear(T array[], size_t n) {
  for (size_t i = 0; i < n; ++i) {
    array[i] = 0;
  }
}

template <typename T, size_t n>
inline void clear(T (&array)[n]) {
  clear(array, n);
}

int int_array[12];

clear(int_array); // deduce T is int, and that n is 12

...

Code Block
bgColor#ffcccc
langcpp

vector<int> table;

int insert_in_table(int pos, int value){
  if (pos >= table.size()) {
    return -1;
  }
  table[pos] = value;
  return 0;
}

...

Code Block
bgColor#ccccff
langcpp

vector<int> table;

int insert_in_table(size_t pos, int value){
  if (pos >= table.size()) {
    return -1;
  }
  table[pos] = value;
  return 0;
}

...

Code Block
bgColor#ccccff
langcpp

vector<int> table;

int insert_in_table(size_t pos, int value){
  table.at(pos) = value;
  return 0;
}

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

ARR30-CPP

high

likely

high

P9

L2

Automated Detection

...

The LDRA tool suite Version 7.6.0 can detect violations of this rule.

...

ToolVersionCheckerDescription
Coverity5.0

...

NEGATIVE_RETURNSImplemented
LDRA7.6 Implemented
Klockwork
8.0.4.16

...

ABR

ABV.TAINTED

...

SV.TAINTED.INDEX_ACCESS

...

Implemented
Compass/ROSE

...

  Implemented

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...