From 8f0c0cfabd3c5f9b2d23fd43da76897ae6e47859 Mon Sep 17 00:00:00 2001 From: Peter Edwards Date: Sat, 19 Aug 2023 16:32:08 +0100 Subject: [PATCH] Do proper handling of signed/unsigned types when parsing flags. --- libpstack/flags.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libpstack/flags.h b/libpstack/flags.h index ea50507..78fe1d1 100644 --- a/libpstack/flags.h +++ b/libpstack/flags.h @@ -11,7 +11,11 @@ namespace { template void convert(const char *opt, T &to) { if constexpr (std::is_integral::value) - to = strtol(opt, 0, 0); + if constexpr (std::is_signed::value) + to = T(strtoll(opt, 0, 0)); + else + to = T(strtoull(opt, 0, 0)); + else if constexpr (std::is_floating_point::value) to = strtod(opt, 0); else