From f5a870a207b62c727dc6b97a31df8d7aedf2aa9f0ba6c583fb51c5eb3e6a4b0e Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Mon, 11 Aug 2025 03:36:00 -0400 Subject: [PATCH] More local string cleanups. --- src/form.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/form.cc b/src/form.cc index 6a60247..3385fc2 100644 --- a/src/form.cc +++ b/src/form.cc @@ -1279,24 +1279,23 @@ char *DilloHtmlFormImpl::makeMultipartBoundary(iconv_t char_encoder, std::string DilloHtmlFormImpl::encodeText(iconv_t char_encoder, std::string &&input) { int rc = 0; - Dstr *output; const int bufsize = 128; inbuf_t *inPtr; - char *buffer, *outPtr; + char *outPtr; size_t inLeft, outRoom; bool bad_chars = false; if ((char_encoder == (iconv_t) -1) || input.empty()) return input; - output = dStr_new(""); + std::string output; inPtr = input.data(); inLeft = input.size(); - buffer = dNew(char, bufsize); + std::vector< char > buffer( bufsize ); while ((rc != EINVAL) && (inLeft > 0)) { - outPtr = buffer; + outPtr = buffer.data(); outRoom = bufsize; rc = iconv(char_encoder, &inPtr, &inLeft, &outPtr, &outRoom); @@ -1309,7 +1308,7 @@ std::string DilloHtmlFormImpl::encodeText(iconv_t char_encoder, std::string &&in // GNU iconv has the undocumented(!) behavior that EILSEQ is also // returned when a character cannot be converted. - dStr_append_l(output, buffer, bufsize - outRoom); + output+= std::string_view{ buffer.data(), buffer.data() + bufsize - outRoom }; if (rc == -1) { rc = errno; @@ -1319,7 +1318,7 @@ std::string DilloHtmlFormImpl::encodeText(iconv_t char_encoder, std::string &&in bad_chars = true; inPtr++; inLeft--; - dStr_append_c(output, '?'); + output+= '?'; } else if (rc == EINVAL) { MSG_ERR("Form encode text: bad source string.\n"); } @@ -1334,11 +1333,7 @@ std::string DilloHtmlFormImpl::encodeText(iconv_t char_encoder, std::string &&in MSG_WARN("Form encode text: string cannot be converted cleanly.\n"); } - dFree(buffer); - - std::string rv= output->str; - dStr_free( output, 1 ); - return rv; + return output; } /**