Skip to content

Commit 8e9d851

Browse files
committed
Fix undefined behaviour in utf16_to_utf8
Fixes SqliteModernCpp#151.
1 parent d7e8c4f commit 8e9d851

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

hdr/sqlite_modern_cpp/utility/utf16_utf8.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <locale>
44
#include <string>
5+
#include <algorithm>
56

67
#include "../errors.h"
78

@@ -10,7 +11,7 @@ namespace sqlite {
1011
inline std::string utf16_to_utf8(const std::u16string &input) {
1112
struct : std::codecvt<char16_t, char, std::mbstate_t> {
1213
} codecvt;
13-
std::mbstate_t state;
14+
std::mbstate_t state{};
1415
std::string result((std::max)(input.size() * 3 / 2, std::size_t(4)), '\0');
1516
const char16_t *remaining_input = input.data();
1617
std::size_t produced_output = 0;

0 commit comments

Comments
 (0)