Skip to content

fix subscript out of range in autovector.h - #379

Merged
emstoudenmire merged 1 commit into
ITensor:v3from
shencebebetterme:fix_subscript
Jan 18, 2021
Merged

fix subscript out of range in autovector.h#379
emstoudenmire merged 1 commit into
ITensor:v3from
shencebebetterme:fix_subscript

Conversation

@shencebebetterme

Copy link
Copy Markdown
Contributor

In "autovector.h", the length of the std::vector dat_ is equal to 1+maxi_-mini_+miniloc_, therefore in the expression dat_[1+maxi_-mini_+miniloc_] the subscript definitely goes out of range.

Previously this issue causes no error because on Linux and on mac std::vector does not perform a bound check and returns whatever in the memory as the out-of-range element. The end() thus obtained still points to the correct memory, however, the above behaviour is undefined and should be avoided.

The fixes are easy.

@emstoudenmire

Copy link
Copy Markdown
Contributor

Thank you for this fix - it's a welcome improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants