From the course: C++ Best Practices for Developers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: Finding issues with Cppcheck - C++ Tutorial
From the course: C++ Best Practices for Developers
Solution: Finding issues with Cppcheck
(tinkling and swooshing) - [Instructor] Did you find the issues in the challenge? Hopefully, you found them all. Let me show you what I found. In fact, let's go to the code, and let's go ahead and do a right click, open it in the terminal, and we're going to do a cppcheck - -enable =all and ./*.cpp, and what we find is it says that it found four errors. Array houseCats accessed at index 2, so this is on line 17, so right here. I'm actually creating two of these items, so there going to be index of zero and one, not two, It's correctly found that. And line 22, there's a bunch going on with this trying to create a file. It's saying that the buffer accessed is out of bounds, a memory leak on buffer, and this is actually very serious, because memory leaks are one of those things that it doesn't kill you at first, but it kills your application eventually and at a random spot, and then it's also another resource leak, because we're not getting rid of the file handle that we've grabbed here.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.