From: Gerhard Sittig Date: Sun, 25 Jun 2023 20:47:47 +0000 (+0200) Subject: strutil: accept 0b prefix when base is 2 (which is non-zero) X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5c462eb3c874ce79ff40eecc3ad9921ede0aad22;p=libsigrok.git strutil: accept 0b prefix when base is 2 (which is non-zero) The sr_atoul_base() conversion routine only accepted the 0b binary prefix when base was 0. Extend this to also accept the 0b prefix when the caller specified base is 2. This unbreaks a valid use case. --- diff --git a/src/strutil.c b/src/strutil.c index c389a524..be07662f 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -174,7 +174,7 @@ SR_PRIV int sr_atoul_base(const char *str, unsigned long *ret, char **end, int b /* Add "0b" prefix support which strtol(3) may be missing. */ while (str && isspace(*str)) str++; - if (!base && strncmp(str, "0b", strlen("0b")) == 0) { + if ((!base || base == 2) && strncmp(str, "0b", strlen("0b")) == 0) { str += strlen("0b"); base = 2; }