You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by pa...@apache.org on 2018/05/04 17:59:01 UTC

[trafficserver] branch master updated: Cache-Tool: coverity Fixes

This is an automated email from the ASF dual-hosted git repository.

paziz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b221cf  Cache-Tool: coverity Fixes
0b221cf is described below

commit 0b221cfa7b2a7cac003a0581a408c70d103b8b05
Author: Persia Aziz <pe...@yahoo-inc.com>
AuthorDate: Thu May 3 17:46:52 2018 -0500

    Cache-Tool: coverity Fixes
---
 cmd/traffic_cache_tool/CacheDefs.cc |  7 +++++--
 cmd/traffic_cache_tool/CacheDefs.h  | 12 ++++++------
 cmd/traffic_cache_tool/CacheScan.cc |  2 +-
 cmd/traffic_cache_tool/File.h       | 27 +++++++++++++++++++++------
 4 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/cmd/traffic_cache_tool/CacheDefs.cc b/cmd/traffic_cache_tool/CacheDefs.cc
index f266fc9..633619d 100644
--- a/cmd/traffic_cache_tool/CacheDefs.cc
+++ b/cmd/traffic_cache_tool/CacheDefs.cc
@@ -463,13 +463,16 @@ Stripe::dir_probe(CryptoHash *key, CacheDirEntry *result, CacheDirEntry **last_c
       e = next_dir(e, seg);
 
     } while (e);
-
+    if (e == nullptr) {
+      std::cout << "No directory entry found matching the URL key" << std::endl;
+      return 0;
+    }
     int fd       = _span->_fd;
     Bytes offset = stripe_offset(e);
     int64_t size = dir_approx_size(e);
     ssize_t n    = pread(fd, stripe_buff2, size, offset);
     if (n < size)
-      std::cout << "Failed to read content from the Stripe:" << strerror(n) << std::endl;
+      std::cout << "Failed to read content from the Stripe:" << strerror(errno) << std::endl;
 
     doc = reinterpret_cast<Doc *>(stripe_buff2);
     std::string hdr(doc->hdr(), doc->hlen);
diff --git a/cmd/traffic_cache_tool/CacheDefs.h b/cmd/traffic_cache_tool/CacheDefs.h
index 2284de9..e3af406 100644
--- a/cmd/traffic_cache_tool/CacheDefs.h
+++ b/cmd/traffic_cache_tool/CacheDefs.h
@@ -444,10 +444,10 @@ struct Span {
   CacheStoreBlocks _base;   ///< Offset to first usable byte.
   CacheStoreBlocks _offset; ///< Offset to first content byte.
   // The space between _base and _offset is where the span information is stored.
-  CacheStoreBlocks _len;         ///< Total length of span.
-  CacheStoreBlocks _free_space;  ///< Total size of free stripes.
-  ink_device_geometry _geometry; ///< Geometry of span.
-  uint64_t num_usable_blocks;    // number of usable blocks for stripes i.e., after subtracting the skip and the disk header.
+  CacheStoreBlocks _len;                                 ///< Total length of span.
+  CacheStoreBlocks _free_space;                          ///< Total size of free stripes.
+  ink_device_geometry _geometry = ink_device_geometry(); ///< Geometry of span.
+  uint64_t num_usable_blocks    = 0; // number of usable blocks for stripes i.e., after subtracting the skip and the disk header.
   /// Local copy of serialized header data stored on in the span.
   std::unique_ptr<ts::SpanHeader> _header;
   /// Live information about stripes.
@@ -516,8 +516,8 @@ struct Stripe {
   int8_t _idx      = -1; ///< Stripe index in span.
   int agg_buf_pos  = 0;
 
-  int64_t _buckets;  ///< Number of buckets per segment.
-  int64_t _segments; ///< Number of segments.
+  int64_t _buckets  = 0; ///< Number of buckets per segment.
+  int64_t _segments = 0; ///< Number of segments.
 
   std::string hashText;
 
diff --git a/cmd/traffic_cache_tool/CacheScan.cc b/cmd/traffic_cache_tool/CacheScan.cc
index 1e7cbd9..f365869 100644
--- a/cmd/traffic_cache_tool/CacheScan.cc
+++ b/cmd/traffic_cache_tool/CacheScan.cc
@@ -54,7 +54,7 @@ CacheScan::Scan()
           int64_t offset = this->stripe->stripe_offset(e);
           ssize_t n      = pread(fd, stripe_buff2, size, offset);
           if (n < size)
-            std::cout << "Failed to read content from the Stripe.  " << strerror(n) << std::endl;
+            std::cout << "Failed to read content from the Stripe.  " << strerror(errno) << std::endl;
           Doc *doc = reinterpret_cast<Doc *>(stripe_buff2);
           get_alternates(doc->hdr(), doc->hlen);
 
diff --git a/cmd/traffic_cache_tool/File.h b/cmd/traffic_cache_tool/File.h
index e282e65..20a77f7 100644
--- a/cmd/traffic_cache_tool/File.h
+++ b/cmd/traffic_cache_tool/File.h
@@ -113,16 +113,31 @@ public:
 
 private:
   std::string _content; ///< The file contents.
-  size_t _len;          ///< Length of file content.
+  size_t _len = -1;     ///< Length of file content.
 };
 
 /* ------------------------------------------------------------------- */
 
-inline FilePath::FilePath() {}
-inline FilePath::FilePath(char const *path) : _path(path) {}
-inline FilePath::FilePath(TextView const &path) : _path(path.data(), path.size()) {}
-inline FilePath::FilePath(self const &that) : _path(that._path) {}
-inline FilePath::FilePath(self &&that) : _path(std::move(that._path)) {}
+inline FilePath::FilePath()
+{
+  ink_zero(_stat);
+}
+inline FilePath::FilePath(char const *path) : _path(path)
+{
+  ink_zero(_stat);
+}
+inline FilePath::FilePath(TextView const &path) : _path(path.data(), path.size())
+{
+  ink_zero(_stat);
+}
+inline FilePath::FilePath(self const &that) : _path(that._path)
+{
+  ink_zero(_stat);
+}
+inline FilePath::FilePath(self &&that) : _path(std::move(that._path))
+{
+  ink_zero(_stat);
+}
 inline FilePath::operator const char *() const
 {
   return _path.c_str();

-- 
To stop receiving notification emails like this one, please contact
paziz@apache.org.