diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2022-10-07 10:38:45 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2022-10-07 10:38:45 +0200 |
commit | 589e2f0d174ca043ac17fe3ae06b7e5532542e9d (patch) | |
tree | 628fec4b60dff4683d844f4b456814f4923fa893 | |
parent | 7c1c779cfd01162d020d0c276bb605adfe338df9 (diff) | |
download | dabmux-589e2f0d174ca043ac17fe3ae06b7e5532542e9d.tar.gz dabmux-589e2f0d174ca043ac17fe3ae06b7e5532542e9d.tar.bz2 dabmux-589e2f0d174ca043ac17fe3ae06b7e5532542e9d.zip |
Make hexparse return unsigned
This fixes the definition of long service IDs on 32-bit systems
-rw-r--r-- | src/utils.cpp | 15 | ||||
-rw-r--r-- | src/utils.h | 2 |
2 files changed, 8 insertions, 9 deletions
diff --git a/src/utils.cpp b/src/utils.cpp index c9a2714..1e006f7 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -554,16 +554,16 @@ void printEnsemble(const shared_ptr<dabEnsemble>& ensemble) } } -long hexparse(const std::string& input) +unsigned long hexparse(const std::string& input) { - long value = 0; + unsigned long value = 0; errno = 0; char* endptr = nullptr; const bool is_hex = (input.find("0x") == 0); - // Do not use strtol's base=0 because + // Do not use strtoul's base=0 because // we do not want to accept octal. const int base = is_hex ? 16 : 10; @@ -573,10 +573,9 @@ long hexparse(const std::string& input) // Comments taken from manpage - value = strtol(startptr, &endptr, base); - if ((value == LONG_MIN or value == LONG_MAX) and errno == ERANGE) { - // If an underflow occurs, strtol() returns LONG_MIN. - // If an overflow occurs, strtol() returns LONG_MAX. + value = strtoul(startptr, &endptr, base); + if (value == ULONG_MAX and errno == ERANGE) { + // If an overflow occurs, strtoul() returns ULONG_MAX. // In both cases, errno is set to ERANGE. throw out_of_range("hexparse: value out of range"); } @@ -588,7 +587,7 @@ long hexparse(const std::string& input) throw invalid_argument(ss.str()); } else if (startptr == endptr) { - // If there were no digits at all, strtol() stores the original value + // If there were no digits at all, strtoul() stores the original value // of nptr in *endptr (and returns 0). throw out_of_range("hexparse: no value found"); } diff --git a/src/utils.h b/src/utils.h index b844676..331a0b2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -73,6 +73,6 @@ void printEnsemble(const std::shared_ptr<dabEnsemble>& ensemble); void printSubchannels(const vec_sp_subchannel& subchannels); -long hexparse(const std::string& input); +unsigned long hexparse(const std::string& input); bool stringEndsWith(std::string const &fullString, std::string const &ending); |