Only call isqrt32() with a positive argument
Fixes test_opus_projection failure under ubsan, due to clz(0).
diff --git a/src/opus_projection_encoder.c b/src/opus_projection_encoder.c
index 1c403c3..1fbcf47 100644
--- a/src/opus_projection_encoder.c
+++ b/src/opus_projection_encoder.c
@@ -86,15 +86,17 @@
/* Allowed numbers of channels:
* (1 + n)^2 + 2j, for n = 0...14 and j = 0 or 1.
*/
+ if (channels < 1 || channels > 227)
+ return OPUS_BAD_ARG;
+
order_plus_one_ = isqrt32(channels);
acn_channels = order_plus_one_ * order_plus_one_;
nondiegetic_channels = channels - acn_channels;
+ if (nondiegetic_channels != 0 && nondiegetic_channels != 2)
+ return OPUS_BAD_ARG;
+
if (order_plus_one)
*order_plus_one = order_plus_one_;
-
- if (order_plus_one_ < 1 || order_plus_one_ > 15 ||
- (nondiegetic_channels != 0 && nondiegetic_channels != 2))
- return OPUS_BAD_ARG;
return OPUS_OK;
}