}
-int int_array_len(const int *a)
+size_t int_array_len(const int *a)
{
- int i;
+ size_t i;
+
for (i = 0; a && a[i]; i++)
;
return i;
void int_array_concat(int **res, const int *a)
{
- int reslen, alen, i, new_len;
+ size_t reslen, alen, i, max_size;
int *n;
reslen = int_array_len(*res);
alen = int_array_len(a);
- new_len = reslen + alen + 1;
- if (reslen < 0 || alen < 0 || new_len < 0) {
+ max_size = (size_t) -1;
+ if (alen >= max_size - reslen) {
/* This should not really happen, but if it did, something
- * overflowed. Do not try to merge the arrays; instead, make
+ * would overflow. Do not try to merge the arrays; instead, make
* this behave like memory allocation failure to avoid messing
* up memory. */
os_free(*res);
*res = NULL;
return;
}
- n = os_realloc_array(*res, new_len, sizeof(int));
+ n = os_realloc_array(*res, reslen + alen + 1, sizeof(int));
if (n == NULL) {
- if (new_len)
- os_free(*res);
+ os_free(*res);
*res = NULL;
return;
}
void int_array_sort_unique(int *a)
{
- int alen;
- int i, j;
+ size_t alen, i, j;
if (a == NULL)
return;
void int_array_add_unique(int **res, int a)
{
- int reslen;
+ size_t reslen, max_size;
int *n;
for (reslen = 0; *res && (*res)[reslen]; reslen++) {
return; /* already in the list */
}
- if (reslen > INT_MAX - 2) {
+ max_size = (size_t) -1;
+ if (reslen > max_size - 2) {
/* This should not really happen in practice, but if it did,
* something would overflow. Do not try to add the new value;
* instead, make this behave like memory allocation failure to
unsigned int freq);
char * freq_range_list_str(const struct wpa_freq_range_list *list);
-int int_array_len(const int *a);
+size_t int_array_len(const int *a);
void int_array_concat(int **res, const int *a);
void int_array_sort_unique(int *a);
void int_array_add_unique(int **res, int a);
int test3[] = { 1, 1, 1, -1, 2, 3, 4, 1, 2, 0 };
int test3_res[] = { -1, 1, 2, 3, 4, 0 };
int errors = 0;
- int len;
+ size_t len;
wpa_printf(MSG_INFO, "int_array tests");