diff options
author | Wayne Davison <wayned@samba.org> | 2015-12-18 14:38:10 -0800 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2015-12-18 14:41:22 -0800 |
commit | 6ff5824c25cdc586b4cd18f1e90fe226f2bf7a59 (patch) | |
tree | d5340bfdacb60299212d4c93f8167399c2e3e57b | |
parent | 32de6b7cb47630c5d5ba3afe631faa42966d8490 (diff) | |
download | android_external_rsync-6ff5824c25cdc586b4cd18f1e90fe226f2bf7a59.tar.gz android_external_rsync-6ff5824c25cdc586b4cd18f1e90fe226f2bf7a59.tar.bz2 android_external_rsync-6ff5824c25cdc586b4cd18f1e90fe226f2bf7a59.zip |
Document expand_item_list's args & make sure incr==0 works OK.
-rw-r--r-- | util.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -1605,6 +1605,12 @@ int flist_ndx_pop(flist_ndx_list *lp) return ndx; } +/* Make sure there is room for one more item in the item list. If there + * is not, expand the list as indicated by the value of "incr": + * - if incr < 0 then increase the malloced size by -1 * incr + * - if incr >= 0 then either make the malloced size equal to "incr" + * or (if that's not large enough) double the malloced size + */ void *expand_item_list(item_list *lp, size_t item_size, const char *desc, int incr) { @@ -1616,9 +1622,11 @@ void *expand_item_list(item_list *lp, size_t item_size, new_size += -incr; /* increase slowly */ else if (new_size < (size_t)incr) new_size = incr; - else + else if (new_size) new_size *= 2; - if (new_size < lp->malloced) + else + new_size = 1; + if (new_size <= lp->malloced) overflow_exit("expand_item_list"); /* Using _realloc_array() lets us pass the size, not a type. */ new_ptr = _realloc_array(lp->items, item_size, new_size); |