ordered-set: avoid overflow

Previously, ordered_set_put_strdupv() and friends returns the number of
pushed entries, but that is potentially larger than INT_MAX (of course,
realistically, OOM is triggered in that case).

No caller uses the number of the new entries. Let's return 1 when at
least one element is added.

Fixes CID#1611523.
This commit is contained in:
Yu Watanabe
2025-07-26 05:00:02 +09:00
parent 6ce3b1fa33
commit 2c3b3e2fd9
2 changed files with 16 additions and 15 deletions
+6 -6
View File
@@ -61,7 +61,7 @@ int ordered_set_put_strdup_full(OrderedSet **s, const struct hash_ops *hash_ops,
}
int ordered_set_put_strdupv_full(OrderedSet **s, const struct hash_ops *hash_ops, char **l) {
int n = 0, r;
int r, ret = 0;
assert(s);
@@ -70,14 +70,14 @@ int ordered_set_put_strdupv_full(OrderedSet **s, const struct hash_ops *hash_ops
if (r < 0)
return r;
n += r;
ret = ret || r > 0;
}
return n;
return ret;
}
int ordered_set_put_string_set_full(OrderedSet **s, const struct hash_ops *hash_ops, OrderedSet *l) {
int n = 0, r;
int r, ret = 0;
char *p;
assert(s);
@@ -89,10 +89,10 @@ int ordered_set_put_string_set_full(OrderedSet **s, const struct hash_ops *hash_
if (r < 0)
return r;
n += r;
ret = ret || r > 0;
}
return n;
return ret;
}
void ordered_set_print(FILE *f, const char *field, OrderedSet *s) {