diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-10-26 08:54:31 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-10-26 19:08:08 +0200 |
commit | b36b24ecfbb7e9fc6c5d5d0a789fabd2a0cb18b3 (patch) | |
tree | f0e0a6d68b618e663a0f5fc9c093073ecabdb564 /xmlhelp | |
parent | d2fccf0117a37f8aab8bb50ece419987f06af6b9 (diff) |
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 <sbergman@redhat.com>
Diffstat (limited to 'xmlhelp')
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/db.cxx | 15 |
1 files changed, 5 insertions, 10 deletions
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}; } } |