From: Mike Stepanek (mstepane) Date: Thu, 16 Sep 2021 15:18:15 +0000 (+0000) Subject: Merge pull request #3058 in SNORT/snort3 from ~SVLASIUK/snort3:clang_tests_fix to... X-Git-Tag: 3.1.13.0~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e2ba3ea1c690102c72e5054c36bd27cb3a56475;p=thirdparty%2Fsnort3.git Merge pull request #3058 in SNORT/snort3 from ~SVLASIUK/snort3:clang_tests_fix to master Squashed commit of the following: commit 5e0b2df7cce8a2dd802bf41fa7c3af47c7120e76 Author: Serhii Vlasiuk Date: Wed Sep 8 17:11:02 2021 +0300 utils: avoid using pubsetbuf which is STL implementation dependent --- diff --git a/src/utils/js_normalizer.cc b/src/utils/js_normalizer.cc index 38ccf0ef5..04db5661c 100644 --- a/src/utils/js_normalizer.cc +++ b/src/utils/js_normalizer.cc @@ -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(tmp_buf_size), tmp_buf); - in_buf.pubsetbuf(tmp_buf, tmp_buf_size, const_cast(src), len); - out_buf.pubsetbuf(dst, dst_len); + in_buf.str(tmp_buf, tmp_buf_size, const_cast(src), len); + size_t w_bytes = out.tellp(); JSTokenizer::JSRet ret = static_cast(tokenizer.yylex()); + + out_buf.sgetn(dst, dst_len); + in.clear(); out.clear(); size_t r_bytes = in_buf.glued() ? static_cast(in.tellg()) : 0; - size_t w_bytes = out.tellp(); + w_bytes = (size_t)out.tellp() - w_bytes; if (!unlim) rem_bytes -= r_bytes; diff --git a/src/utils/js_normalizer.h b/src/utils/js_normalizer.h index 9bbbeb8a5..a58a45d22 100644 --- a/src/utils/js_normalizer.h +++ b/src/utils/js_normalizer.h @@ -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(); }