From b905ccfeb643185be03b818df780867fe987937d Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 28 Apr 2011 15:55:52 -0400 Subject: [PATCH] --- yaml --- r: 250804 b: refs/heads/master c: 150cdf6ec0ede8d9f102f1817212447727dcf08c h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/lib/flex_array.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index 144a0af20fe4..1180fd29fe2d 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 5a3ea8782c63d3501cb764c176f153c0d9a400e1 +refs/heads/master: 150cdf6ec0ede8d9f102f1817212447727dcf08c diff --git a/trunk/lib/flex_array.c b/trunk/lib/flex_array.c index 0c33b24498ba..854b57bd7d9d 100644 --- a/trunk/lib/flex_array.c +++ b/trunk/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++) {