]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Simplify appending SBuf to String (#2108) auto master
authorAlex Rousskov <rousskov@measurement-factory.com>
Mon, 30 Jun 2025 20:32:16 +0000 (20:32 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 2 Jul 2025 01:50:15 +0000 (01:50 +0000)
There is still a lot of code that uses legacy String class, and an
increasing amount of code that has to append modern SBufs to Strings.

SBuf handles NUL bytes better than String. With respect to handling NUL
bytes, the new append() method is as (un)safe as the existing explicit
size-based one (that callers tend to use prior to these changes anyway).

src/SquidString.h
src/String.cc
src/clients/FtpGateway.cc
src/ipc/Port.cc
src/ipc/mem/Segment.cc

index 1851eaae49d0b2153a9bc5c275e3b6d47cd86cdf..ab8125b10bd1954644aa98f0ed4a39cf45299aa3 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "base/TextException.h"
 #include "debug/Stream.h"
 
 #include "base/TextException.h"
 #include "debug/Stream.h"
+#include "sbuf/forward.h"
 
 #include <ostream>
 
 
 #include <ostream>
 
@@ -98,6 +99,7 @@ public:
     void append(char const *buf);
     void append(char const);
     void append(String const &);
     void append(char const *buf);
     void append(char const);
     void append(String const &);
+    void append(const SBuf &); ///< adds the entire given buffer
     void absorb(String &old);
     const char * pos(char const *aString) const;
     const char * pos(char const ch) const;
     void absorb(String &old);
     const char * pos(char const *aString) const;
     const char * pos(char const ch) const;
index 79fe1a2e1041737ccd8f536ceac13db3d05e17a1..45e24c94828b90130d427a161622b6f7f6214bcf 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "squid.h"
 #include "mem/forward.h"
 
 #include "squid.h"
 #include "mem/forward.h"
+#include "sbuf/SBuf.h"
 #include "SquidString.h"
 
 #include <climits>
 #include "SquidString.h"
 
 #include <climits>
@@ -175,6 +176,12 @@ String::append(String const &old)
     append(old.rawBuf(), old.len_);
 }
 
     append(old.rawBuf(), old.len_);
 }
 
+void
+String::append(const SBuf &buf)
+{
+    append(buf.rawContent(), buf.length());
+}
+
 void
 String::absorb(String &old)
 {
 void
 String::absorb(String &old)
 {
index fc0f3a2e94d6824f206d65e9ff8dfe08551a9a62..ddf96160293c9523da4f895b44380300e9432be6 100644 (file)
@@ -1122,8 +1122,8 @@ Ftp::Gateway::buildTitleUrl()
 
     SBuf authority = request->url.authority(request->url.getScheme() != AnyP::PROTO_FTP);
 
 
     SBuf authority = request->url.authority(request->url.getScheme() != AnyP::PROTO_FTP);
 
-    title_url.append(authority.rawContent(), authority.length());
-    title_url.append(request->url.path().rawContent(), request->url.path().length());
+    title_url.append(authority);
+    title_url.append(request->url.path());
 
     base_href = "ftp://";
 
 
     base_href = "ftp://";
 
@@ -1138,8 +1138,8 @@ Ftp::Gateway::buildTitleUrl()
         base_href.append("@");
     }
 
         base_href.append("@");
     }
 
-    base_href.append(authority.rawContent(), authority.length());
-    base_href.append(request->url.path().rawContent(), request->url.path().length());
+    base_href.append(authority);
+    base_href.append(request->url.path());
     base_href.append("/");
 }
 
     base_href.append("/");
 }
 
index 2446d1bb7a6454a20fd6c2fc07f76bd17d245b08..566327f2d4b0a51fadd3d6ff61382ab12f06bdc3 100644 (file)
@@ -53,7 +53,7 @@ String Ipc::Port::MakeAddr(const char* processLabel, int id)
 {
     assert(id >= 0);
     String addr = channelPathPfx;
 {
     assert(id >= 0);
     String addr = channelPathPfx;
-    addr.append(service_name.c_str());
+    addr.append(service_name);
     addr.append(processLabel);
     addr.append('-');
     addr.append(xitoa(id));
     addr.append(processLabel);
     addr.append('-');
     addr.append(xitoa(id));
@@ -67,7 +67,7 @@ Ipc::Port::CoordinatorAddr()
     static String coordinatorAddr;
     if (!coordinatorAddr.size()) {
         coordinatorAddr= channelPathPfx;
     static String coordinatorAddr;
     if (!coordinatorAddr.size()) {
         coordinatorAddr= channelPathPfx;
-        coordinatorAddr.append(service_name.c_str());
+        coordinatorAddr.append(service_name);
         coordinatorAddr.append(coordinatorAddrLabel);
         coordinatorAddr.append(".ipc");
     }
         coordinatorAddr.append(coordinatorAddrLabel);
         coordinatorAddr.append(".ipc");
     }
index 67ba4431f153214fd1b17e0c7f82242a22ec9711..dbd458b57a53405704c4b839441e9fa73393f37a 100644 (file)
@@ -278,7 +278,7 @@ Ipc::Mem::Segment::GenerateName(const char *id)
             name.append('/');
     } else {
         name.append('/');
             name.append('/');
     } else {
         name.append('/');
-        name.append(service_name.c_str());
+        name.append(service_name);
         name.append('-');
     }
 
         name.append('-');
     }