Re: [googletest] gtest is not coverity-clean

669 views
Skip to first unread message

Zhanyong Wan (λx.x x)

unread,
Mar 14, 2013, 6:15:28 PM3/14/13
to Dan Kegel, Google C++ Testing Framework
Thanks for the report, Dan.

Looks like you are using an older version of gtest, as the variable pretty_ mentioned in the report was already removed from trunk.  Is it possible that you run coverity on the trunk head of gtest?  Thanks,


On Thu, Mar 14, 2013 at 2:59 PM, Dan Kegel <daniel....@gmail.com> wrote:
Coverity is a nice static analyzer for C++ projects.
It complains about a few things in google test.
Some of them are silly, but a couple of them might be worth looking at.

File: gtest_main.cc

  
CID 10124 (#2 of 2): Uncaught exception (UNCAUGHT_EXCEPT)root_function: In function "main" an exception of type "testing::internal::<unnamed>::ClassUniqueToAlwaysTrue" is thrown and never caught.
34GTEST_API_ int main(int argcchar **argv) {

File: gtest_all.cc

 548class GTestFlagSaver {
 549 public:
 550  // The c'tor.
 551  GTestFlagSaver() {
...
 567    stream_result_to_ = GTEST_FLAG(stream_result_to);
 568    throw_on_failure_ = GTEST_FLAG(throw_on_failure);
    
CID 10132 (#2 of 2): Uninitialized scalar field (UNINIT_CTOR)2. uninit_member: Non-static class member "pretty_" is not initialized in this constructor nor in any functions that it calls.
 569  }

8323  ~CapturedStream() {
    
CID 10023 (#2 of 2): Unchecked return value from library (CHECKED_RETURN)1. check_return: Calling function "remove(this->filename_.c_str())" without checking return value. This library function may fail and return an error code.
    
2. unchecked_value: No check of the return value of "remove(this->filename_.c_str())".
8324    remove(filename_.c_str());
8325  }
8326

8290class CapturedStream {
8291 public:
8292  // The ctor redirects the stream to a temporary file.
    
CID 10051 (#2 of 2): Resource leak in object (CTOR_DTOR_LEAK)1. alloc_fn: Calling allocation function "dup(int)".
    
2. var_assign: Assigning: "this->uncaptured_fd_" = "dup(fd)".
    
3. ctor_dtor_leak: The constructor allocates field "uncaptured_fd_" of "testing::internal::CapturedStream" but the destructor and whatever functions it calls do not free it.
8293  CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {











8364String CapturedStream::ReadEntireFile(FILEfile) {
    
1. negative_return_fn: Function "testing::internal::CapturedStream::GetFileSize(file)" returns a negative number. [show details]
    
2. var_assign: Assigning: unsigned variable "file_size" = "testing::internal::CapturedStream::GetFileSize(FILE *)".
8365  const size_t file_size = GetFileSize(file);
    
CID 10074 (#2 of 2): Argument cannot be negative (NEGATIVE_RETURNS)3. negative_returns: "file_size" is passed to a parameter that cannot be negative.
8366  charconst buffer = new char[file_size];

8314    char name_template[] = "/tmp/captured_stream.XXXXXX";
    
1. negative_return_fn: Function "mkstemp(name_template)" returns a negative number.
    
2. var_assign: Assigning: signed variable "captured_fd" = "mkstemp(char *)".
8315    const int captured_fd = mkstemp(name_template);
8316    filename_ = name_template;
8317# endif  // GTEST_OS_WINDOWS
8318    fflush(NULL);
    
CID 10075 (#2 of 2): Argument cannot be negative (NEGATIVE_RETURNS)3. negative_returns: "captured_fd" is passed to a parameter that cannot be negative.
8319    dup2(captured_fdfd_);














--
 
---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Zhanyong

Dan Kegel

unread,
Apr 29, 2013, 4:08:36 PM4/29/13
to Zhanyong Wan (λx.x x), Google C++ Testing Framework
On Thu, Mar 14, 2013 at 3:15 PM, Zhanyong Wan (λx.x x) <w...@google.com> wrote:
> Thanks for the report, Dan.
>
> Looks like you are using an older version of gtest, as the variable pretty_
> mentioned in the report was already removed from trunk. Is it possible that
> you run coverity on the trunk head of gtest?

I've done this with trunk, and sent Zhanyong the results. Hopefully
googletest 1.7 will be coverity-clean.

Meanwhile, here's a patch that gets rid of all the warnings my first
app hits on the most recent googletest release, 1.6.
Comments welcome...
- Dan
gtest16-coverity.patch

Dan Kegel

unread,
May 1, 2013, 3:14:28 PM5/1/13
to Zhanyong Wan (λx.x x), Google C++ Testing Framework
Oh, also need this bit.

--- a/gtest/gtest_main.cc
+++ b/gtest/gtest_main.cc
@@ -34,6 +34,7 @@
GTEST_API_ int main(int argc, char **argv) {
std::cout << "Running main() from gtest_main.cc\n";

+ // coverity[fun_call_w_exception]: uncaught exceptions cause
nonzero exit anyway, so don't warn.
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Reply all
Reply to author
Forward
0 new messages