X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fstrutil.c;h=050f37bf7090532cc67282e07c10ce2867a985b6;hb=HEAD;hp=841a682a2f4b89779043704c279e0c406eb244ab;hpb=a2f3645bcf73a421192591fc7d2d030f9997fda7;p=libsigrok.git diff --git a/src/strutil.c b/src/strutil.c index 841a682a..2136bd49 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -1844,8 +1844,18 @@ SR_API int sr_next_power_of_two(size_t value, size_t *bits, size_t *power) if (power) *power = 0; - if (!value) - return SR_ERR_ARG; + /* + * Handle the special case of input value 0 (needs 1 bit + * and results in "power of two" value 1) here. It is not + * covered by the generic logic below. + */ + if (!value) { + if (bits) + *bits = 1; + if (power) + *power = 1; + return SR_OK; + } need_bits = 0; check_mask = 0;