]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix for Coverity Scan false positives in SBuf
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 6 Feb 2015 21:23:19 +0000 (13:23 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 6 Feb 2015 21:23:19 +0000 (13:23 -0800)
Coverity scanner gets badly confused with SBuf::npos being used as
default parameter value, even though its used to indicate that
strlen() needs to be used on the string.

This is an experiment to see if it gets less confused by having
explicit overloads for the two cases and not using SBuf::npos value
in relation to the unknown length c-strings.

src/SBuf.cc
src/SBuf.h

index 146819283543f41bc8b57c8c1a3424360952db3f..0aa9801e04f660a874c329ed391d534ad4ba130d 100644 (file)
@@ -208,10 +208,8 @@ SBuf::append(const SBuf &S)
 SBuf &
 SBuf::append(const char * S, size_type Ssize)
 {
-    if (S == NULL)
+    if (!S)
         return *this;
-    if (Ssize == SBuf::npos)
-        Ssize = strlen(S);
     debugs(24, 7, "from c-string to id " << id);
     // coverity[access_dbuff_in_call]
     return lowAppend(S, Ssize);
index 7434726126cf5a258dfd7726695d8c8372b950e2..7a0a0e9a252f66604ea5f3da92033296c7629ef6 100644 (file)
@@ -212,13 +212,19 @@ public:
      * as needed.
      *
      * \param S the c string to be copied. Can be NULL.
-     * \param Ssize how many bytes to import into the SBuf. If it is npos
-     *              or unspecified, imports to end-of-cstring. If S is NULL,
-     *              Ssize is ignored.
+     * \param Ssize how many bytes to import into the SBuf.
+     *              If S is NULL, Ssize is ignored.
      * \note to append a std::string use the pattern
      *     cstr_append(stdstr.data(), stdstd.length())
      */
-    SBuf& append(const char * S, size_type Ssize = npos);
+    SBuf& append(const char * S, size_type Ssize);
+
+    /// \see SBuf& append(const char * S, size_type Ssize)
+    SBuf& append(const char * S) {
+        if (!S)
+            return *this;
+        return append(S, strlen(S));
+    }
 
     /** Assignment operation with printf(3)-style definition
      * \note arguments may be evaluated more than once, be careful