Skip to content

Commit 2cfb03e

Browse files
committed
fix appimage build
1 parent cbbae52 commit 2cfb03e

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/util.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,19 @@ bool parse_hex_rgba(const std::string_view hex, rgba_t& out)
387387
if (hex.size() != 7 && hex.size() != 9)
388388
return false;
389389

390-
uint32_t value;
391-
const std::string_view s = hex.data() + 1;
392-
if (std::from_chars(s.data(), s.data() + s.size(), value, 16).ec != std::errc())
390+
// strtoul needs a null-terminated string. Construct one explicitly
391+
// from the substring
392+
const std::string s(hex.substr(1));
393+
394+
char* end = nullptr;
395+
unsigned long parsed = std::strtoul(s.c_str(), &end, 16);
396+
397+
// Ensure the entire string was consumed and no overflow occurred.
398+
if (end != s.c_str() + s.size() || parsed > 0xFFFFFFFFul)
393399
return false;
394400

395-
rgba_t v(hex.size() == 7 ? (value << 8) : value);
396-
if (hex.size() == 7)
397-
v.a = 0xFF;
401+
const auto value = static_cast<uint32_t>(parsed);
402+
rgba_t v(hex.size() == 7 ? (value << 8) | 0xFF : value);
398403

399404
out = v;
400405
return true;

0 commit comments

Comments
 (0)