diff options
Diffstat (limited to 'lib/flex_array.c')
-rw-r--r-- | lib/flex_array.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/flex_array.c b/lib/flex_array.c index 0c33b24498ba..854b57bd7d9d 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, | |||
253 | unsigned int end; | 253 | unsigned int end; |
254 | struct flex_array_part *part; | 254 | struct flex_array_part *part; |
255 | 255 | ||
256 | if (!start && !nr_elements) | ||
257 | return 0; | ||
258 | if (start >= fa->total_nr_elements) | ||
259 | return -ENOSPC; | ||
260 | if (!nr_elements) | ||
261 | return 0; | ||
262 | |||
256 | end = start + nr_elements - 1; | 263 | end = start + nr_elements - 1; |
257 | 264 | ||
258 | if (start >= fa->total_nr_elements || end >= fa->total_nr_elements) | 265 | if (end >= fa->total_nr_elements) |
259 | return -ENOSPC; | 266 | return -ENOSPC; |
260 | if (elements_fit_in_base(fa)) | 267 | if (elements_fit_in_base(fa)) |
261 | return 0; | 268 | return 0; |
@@ -346,6 +353,8 @@ int flex_array_shrink(struct flex_array *fa) | |||
346 | int part_nr; | 353 | int part_nr; |
347 | int ret = 0; | 354 | int ret = 0; |
348 | 355 | ||
356 | if (!fa->total_nr_elements) | ||
357 | return 0; | ||
349 | if (elements_fit_in_base(fa)) | 358 | if (elements_fit_in_base(fa)) |
350 | return ret; | 359 | return ret; |
351 | for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) { | 360 | for (part_nr = 0; part_nr < FLEX_ARRAY_NR_BASE_PTRS; part_nr++) { |