Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elastic array wrap around bug #595

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion libcperciva/datastruct/elasticarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ resize(struct elasticarray * EA, size_t nsize)
if (EA->alloc < nsize) {
/* We need to enlarge the buffer. */
nalloc = EA->alloc * 2;
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one more nitpick: please add a blank line before this comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on second thought, never mind.

I don't know why github isn't running the Actions tests on this PR. Based on the documentation I've found, it should be working now. :(

I'm going to make a new PR (from my own account) with these commits, plus that "blank line" nitpick. That's the only guaranteed way I know of getting github Actions to work, and that'll let the review go through faster.

* Handle if nalloc is not large enough to hold nsize, which can
* happen when: 1) EA->alloc is small enough that EA->alloc * 2
* is still smaller than nsize, or 2) EA->alloc is large enough
* that EA->alloc * 2 wraps around, becoming smaller than nsize.
*/
if (nalloc < nsize)
nalloc = nsize;
} else if (EA->alloc > nsize * 4) {
} else if (EA->alloc / 4 > nsize) {
/* We need to shrink the buffer. */
nalloc = nsize * 2;
} else {
Expand Down