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

Conversation

dorjoy03
Copy link
Contributor

@dorjoy03 dorjoy03 commented Oct 20, 2023

Commits picked up from #592.

Two things:

  1. There was a unsigned wrap around bug in the elasticarray resize code which could cause the buffer to become smaller than the given nsize. I don't really know if it could happen in practice or what problems could be caused in case it happens.
  2. Added a comment explaining that another wrap around is actually handled as it was unclear from just the code.

In the case of modulo wrapping of nsize * 4, the else if block could be
taken even though EA->alloc is not really greater than nsize * 4.  This
can lead to nalloc becoming smaller than nsize, which will result in the
buffer to be reallocated to be smaller than the desired nsize.
This commit adds a comment describing the cases handled by the
if (nalloc < nsize) block.  One such case is the potential wrap
around of EA->alloc * 2.  Without the comment, it was not clear
that the wrap around is properly handled.
@dorjoy03 dorjoy03 mentioned this pull request Oct 20, 2023
@@ -28,6 +28,12 @@ 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.

@gperciva
Copy link
Member

This is continued in #596, due to github Actions not running on this PR.

@gperciva gperciva closed this Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants