xmlhelp/source/cxxhelp/provider/db.cxx |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

New commits:
commit b36b24ecfbb7e9fc6c5d5d0a789fabd2a0cb18b3
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Thu Oct 26 08:54:31 2023 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Thu Oct 26 19:08:08 2023 +0200

    Use std::from_chars
    
    (which also makes readInt32 report failure, instead of running into UB, 
when the
    read value is out of range)
    
    Change-Id: I8449e4fe696c9b0ab5b868127ef517dc080c31ba
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158489
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/xmlhelp/source/cxxhelp/provider/db.cxx 
b/xmlhelp/source/cxxhelp/provider/db.cxx
index bf3c269b99ca..d60bff78ee63 100644
--- a/xmlhelp/source/cxxhelp/provider/db.cxx
+++ b/xmlhelp/source/cxxhelp/provider/db.cxx
@@ -20,28 +20,23 @@
 
 #include "db.hxx"
 
+#include <algorithm>
+#include <charconv>
 #include <cstring>
+#include <system_error>
 #include <utility>
 
 #include <com/sun/star/io/XSeekable.hpp>
-#include <tools/inetmime.hxx>
 
 using namespace com::sun::star::uno;
 using namespace com::sun::star::io;
 
 namespace {
 
-//TODO: Replace with C++17 std::from_chars once available:
 std::pair<sal_Int32, char const *> readInt32(char const * begin, char const * 
end) {
     sal_Int32 n = 0;
-    for (; begin != end; ++begin) {
-        auto const w = INetMIME::getHexWeight(static_cast<unsigned 
char>(*begin));
-        if (w == -1) {
-            break;
-        }
-        n = 16 * n + w;
-    }
-    return {n, begin};
+    auto const [ptr, ec] = std::from_chars(begin, end, n, 16);
+    return {std::max(n, sal_Int32(0)), ec == std::errc{} && n >= 0 ? ptr : 
begin};
 }
 
 }

Reply via email to