Memory leaks

Hello,
i'm searching a programm that can detect a special type of memory leaks, like these:

1
2
3
int a = 12;
char c[10];
char cc = c[a];


thanks Jan
This is not a leak. It is undefined behavior here. You want a static code analyser.
There is free one in clang, there in cppcheck and I believe Visual studio has one too.
i will try the one from Visual Studio,
thanks :)
Or, y'know, use vectors rather than C-style arrays.
Accessing wrong index is a problem with vectors too.
yea but at least is a lot more obvious where the issue might be with vectors.
yea but at least is a lot more obvious where the issue might be with vectors.

How so? If the code were:
1
2
3
int a = 12;
vector<char> c(10);
char cc = c[a];
then wouldn't the problem be the same?
Last edited on
then wouldn't the problem be the same?

With some compilers you can enable bound checks for vector's operator[]. In GCC it will do bounds checking if you define the macro _GLIBCXX_DEBUG. I guess you can do something similar in Visual C++.
> I guess you can do something similar in Visual C++

With Visual C++, #define _SECURE_SCL 1 gives checked element access and range-checked iterators.
http://msdn.microsoft.com/en-us/library/vstudio/aa985965(v=vs.120).aspx

With any implementation, at() provides bounds checked element access.
Last edited on
Topic archived. No new replies allowed.