From rw at firstpr.com.au Mon Oct 14 08:33:22 2019 From: rw at firstpr.com.au (Robin Whittle) Date: Mon, 14 Oct 2019 12:33:22 -0000 Subject: [CoinUtils] Potential bug in CoinIndexedVector::reserve() Message-ID: Though there hasn't been a message on this list for 2 years . . . we are instructed to report bugs to the relevant list. In CoinUtils 2.11.2 and 2.11.3 - and I guess earlier versions, but I haven't checked - the code in CoinIndexedVector.cpp for CoinIndexedVector::reserve() differs from that from version 2.10.11. See the attached image to see how the two differ. I am using 2.10.11 and have no plans to use the later code, but I did notice one or two things which look wrong in these later versions. In 2.10.11, reserve() takes no action if the requested capacity == the current capacity. if (n < capacity_) {...} else if (n > capacity_) This looks correct to me. In the new versions, it takes one kind of action (line 541 in 2.11.3, with some added parentheses for clarity): if ((n + nPlus) < capacity_) and the other if (line 556): else if (n > capacity_) I suspect that line 556 should be: else if ((n + nPlus) > capacity_) which would replicate the prior no action arrangement if n == capacity_. Functionally, the code may still work OK, but it looks wrong to me and there are no comments to explain why it is so. nPlus seems to be set according to the size of integers and I guess it represents the extra data items in the object beyond the two arrays: int nElements_; int capacity_; int offset_; bool packedMode_; Also, given line 541, it seems odd that line 585 remains: capacity_ = n; The intended functionality of the various parts of this function could have been clearly described with suitable comments. Then I wouldn't have to guess about what it is supposed to do. In the absence of such comments I can't know for sure what it supposed to do, but I wanted to point out what seems to me like potential problems. Robin -------------- next part -------------- A non-text attachment was scrubbed... Name: CoinUtills-CoinIndexedVector-compare.png Type: image/png Size: 104155 bytes Desc: not available URL: