]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/generic/array: extend the return type of array_push*() docs-develop-cove-uiak3c/deployments/5118
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 12 Sep 2024 12:54:16 +0000 (14:54 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 12 Sep 2024 13:37:21 +0000 (15:37 +0200)
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.

lib/generic/array.h

index 9bea546be1e55917cd19c925a4289b35b3ba8e75..eb1f7bc253318c70358c53cdef633107d15342f2 100644 (file)
@@ -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++)))