From: Vladimír Čunát Date: Thu, 12 Sep 2024 12:54:16 +0000 (+0200) Subject: lib/generic/array: extend the return type of array_push*() X-Git-Tag: v6.0.9~16^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20f67c0925fd6b050efcf565714720679f1fcd33;p=thirdparty%2Fknot-resolver.git lib/generic/array: extend the return type of array_push*() In case of no error, the index is returned, but `int` isn't a great choice for returning array indices. (though I doubt that we can get anywhere near 2^31 elements in practice) Detected by Coverity. --- diff --git a/lib/generic/array.h b/lib/generic/array.h index 9bea546be..eb1f7bc25 100644 --- a/lib/generic/array.h +++ b/lib/generic/array.h @@ -122,7 +122,7 @@ static inline void array_std_free(void *baton, void *p) * @return element index on success, <0 on failure */ #define array_push_mm(array, val, reserve, baton) \ - (int)((array).len < (array).cap ? ((array).at[(array).len] = (val), (array).len++) \ + (ssize_t)((array).len < (array).cap ? ((array).at[(array).len] = (val), (array).len++) \ : (array_reserve_mm(array, ((array).cap + 1), reserve, baton) < 0 ? -1 \ : ((array).at[(array).len] = (val), (array).len++)))