Examples of Linticator Messages and Fixes¶
The following class has several problems that demonstrate some of Linticator's Quick Fixes:
#include <string>
#include <vector>
#include "LinticatorDemo.h"
#include "LinticatorDemo.h"
struct LinticatorDemo {
/*
* This function should be declared virtual:
*/
void shouldBeVirtual() = 0;
/* The following function shows several problems:
*
* - the parameter s could be made const
* - the function could be made const
* - not all paths return a value
* - the local variable is unused
*/
std::string couldBeMadeConst(std::string& s) {
int unused;
if (1 == 2) {
} else {
return s;
}
}
void copy() {
std::vector<int> in, out;
// the return value of copy is ignored:
std::copy(in.begin(), in.end(), out.begin());
}
};
And here is how this will look like with Linticator's editor annotations:
Here's another one, how quickly can you spot the error?
int a[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int sum(int a[3][3]) {
int i = 0, j = 0, k = 0;
for (i = 0; i < 3; i++) {
for (i = 0; i < 3; i++) {
k += a[i][j];
}
}
return k;
}
For more Lint examples, take a look at Gimpel's Software Bug of the Month.