]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #3058 in SNORT/snort3 from ~SVLASIUK/snort3:clang_tests_fix to...
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Thu, 16 Sep 2021 15:18:15 +0000 (15:18 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Thu, 16 Sep 2021 15:18:15 +0000 (15:18 +0000)
Squashed commit of the following:

commit 5e0b2df7cce8a2dd802bf41fa7c3af47c7120e76
Author: Serhii Vlasiuk <svlasiuk@cisco.com>
Date:   Wed Sep 8 17:11:02 2021 +0300

    utils: avoid using pubsetbuf which is STL implementation dependent

src/utils/js_normalizer.cc
src/utils/js_normalizer.h

index 38ccf0ef53299afb2be53ad135c99ff7447be3d6..04db5661cce5ea5ddb2d957fae4c9c07e7e1b193 100644 (file)
@@ -66,14 +66,17 @@ JSTokenizer::JSRet JSNormalizer::normalize(const char* src, size_t src_len, char
     debug_logf(4, http_trace, TRACE_JS_DUMP, nullptr,
         "tmp buffer[%zu]: %.*s\n", tmp_buf_size, static_cast<int>(tmp_buf_size), tmp_buf);
 
-    in_buf.pubsetbuf(tmp_buf, tmp_buf_size, const_cast<char*>(src), len);
-    out_buf.pubsetbuf(dst, dst_len);
+    in_buf.str(tmp_buf, tmp_buf_size, const_cast<char*>(src), len);
+    size_t w_bytes = out.tellp();
 
     JSTokenizer::JSRet ret = static_cast<JSTokenizer::JSRet>(tokenizer.yylex());
+
+    out_buf.sgetn(dst, dst_len);
+
     in.clear();
     out.clear();
     size_t r_bytes = in_buf.glued() ? static_cast<size_t>(in.tellg()) : 0;
-    size_t w_bytes = out.tellp();
+    w_bytes = (size_t)out.tellp() - w_bytes;
 
     if (!unlim)
         rem_bytes -= r_bytes;
index 9bbbeb8a507b9ee768438f32836609a08572bc93..a58a45d22d0cc36eca7edbb1bdac8864c3e7b434 100644 (file)
@@ -37,19 +37,19 @@ public:
         src1(nullptr), len1(0), src2(nullptr), len2(0)
     { }
 
-    std::streambuf* pubsetbuf(char* buf1, std::streamsize buf1_len,
+    std::streambuf* str(char* buf1, std::streamsize buf1_len,
         char* buf2, std::streamsize buf2_len)
     {
         once = !(buf1 && buf1_len);
 
         if (once)
         {
-            setbuf(buf2, buf2_len);
+            std::stringbuf::str(std::string(buf2, buf2_len));
             current_src_len = buf2_len;
         }
         else
         {
-            setbuf(buf1, buf1_len);
+            std::stringbuf::str(std::string(buf1, buf1_len));
             current_src_len = buf1_len;
         }
         src1 = buf1;
@@ -79,7 +79,7 @@ protected:
 
             off += current_src_len;
             once = false;
-            setbuf(src1, len1);
+            std::stringbuf::str(std::string(src1, len1));
             current_src_len = len1;
         }
 
@@ -100,7 +100,7 @@ protected:
             src1, len1, src2, len2);
 
         once = true;
-        setbuf(src2, len2);
+        std::stringbuf::str(std::string(src2, len2));
         current_src_len = len2;
         return sgetc();
     }