Skip to content

Commit cd0d082

Browse files
committed
Explicit unsigned -> uint16_t casts to avoid conversion warnings
1 parent c749b8f commit cd0d082

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/util/unicode.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ std::vector<std::string> narrow_argv(int argc, const wchar_t **argv_wide)
171171
/// \return A 16-bit integer with bytes swapped
172172
uint16_t do_swap_bytes(uint16_t x)
173173
{
174-
uint16_t b1=x & 0xFF;
175-
uint16_t b2=x & 0xFF00;
174+
const uint16_t b1 = x & 0xFFu;
175+
const uint16_t b2 = x & 0xFF00u;
176176
return (b1 << 8) | (b2 >> 8);
177177
}
178178

@@ -185,7 +185,8 @@ void utf16_append_code(unsigned int code, bool swap_bytes, std::wstring &result)
185185
if(code<0xFFFF)
186186
{ // code is encoded as one UTF16 character
187187
// we just take the code and possibly swap the bytes
188-
unsigned int a=(swap_bytes)?do_swap_bytes(code):code;
188+
const unsigned int a =
189+
swap_bytes ? do_swap_bytes(static_cast<uint16_t>(code)) : code;
189190
result+=static_cast<wchar_t>(a);
190191
}
191192
else // code is encoded as two UTF16 characters
@@ -196,11 +197,11 @@ void utf16_append_code(unsigned int code, bool swap_bytes, std::wstring &result)
196197

197198
// encode the code in UTF16, possibly swapping bytes.
198199
code=code-0x10000;
199-
unsigned int i1=((code>>10) & 0x3ff) | 0xD800;
200-
unsigned int a1=(swap_bytes)?do_swap_bytes(static_cast<uint16_t>(i1)):i1;
200+
const uint16_t i1 = static_cast<uint16_t>(((code >> 10) & 0x3ff) | 0xD800);
201+
const uint16_t a1 = swap_bytes ? do_swap_bytes(i1) : i1;
201202
result+=static_cast<wchar_t>(a1);
202-
unsigned int i2=(code & 0x3ff) | 0xDC00;
203-
unsigned int a2=(swap_bytes)?do_swap_bytes(static_cast<uint16_t>(i2)):i2;
203+
const uint16_t i2 = static_cast<uint16_t>((code & 0x3ff) | 0xDC00);
204+
const uint16_t a2 = swap_bytes ? do_swap_bytes(i2) : i2;
204205
result+=static_cast<wchar_t>(a2);
205206
}
206207
}

0 commit comments

Comments
 (0)