aboutsummaryrefslogtreecommitdiffstats
path: root/lib/flex_array.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/flex_array.c')
-rw-r--r--lib/flex_array.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/flex_array.c b/lib/flex_array.c
index 0c33b24..854b57b 100644
--- a/lib/flex_array.c
+++ b/lib/flex_array.c
@@ -253,9 +253,16 @@ int flex_array_prealloc(struct flex_array *fa, unsigned int start,
unsigned int end;
struct flex_array_part *part;
+ if (!start && !nr_elements)
+ return 0;
+ if (start >= fa->total_nr_elements)
+ return -ENOSPC;
+ if (!nr_elements)
+ return 0;
+
end = start + nr_elements - 1;
- if (start >= fa->total_nr_elements || end >= fa->total_nr_elements)
+ if (end >= fa->total_nr_elements)
return -ENOSPC;
if (elements_fit_in_base(fa))
return 0;
@@ -346,6 +353,8 @@ int flex_array_shrink(struct flex_array *fa)
int part_nr;
int ret = 0;
+ if (!fa->total_nr_elements)
+ return 0;
if (elements_fit_in_base(fa))
return ret;
for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) {