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

Change &foo[0] to foo.data() for a std::vector #2276

Merged
merged 2 commits into from
May 24, 2021
Merged

Change &foo[0] to foo.data() for a std::vector #2276

merged 2 commits into from
May 24, 2021

Conversation

eric-hughes-tiledb
Copy link
Contributor

The idiom &foo[0] is fine for an array; it's not the same for a vector. Accessing a non-existent element through operator[] is undefined behavior, triggered when foo is empty. It's compliant behavior for a library to throw an assertion failure in this case (that's how the defect came to light). The standard library provides data() to substitute for the old, C-style idiom.


TYPE: BUG
DESC: Treating std::vector like an array; accessing an element that's not present to get its address.

Copy link
Contributor

@joe-maley joe-maley left a comment

Choose a reason for hiding this comment

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

LGTM at face value. If this was actually triggering an error, we should put a check that data is non-empty.

@joe-maley
Copy link
Contributor

Also note that you'll need to clang-format this, but I assume you will see that in the related CI failures.

@dhoke4tdb
Copy link
Contributor

LGTM at face value. If this was actually triggering an error, we should put a check that data is non-empty.

My recollection is that the called set_buffer() will properly handle empty .data() (being also passed data.size()), that the error is in appropriate use of vector methods, not a problem with the actual tiledb data.

@eric-hughes-tiledb
Copy link
Contributor Author

the error is in appropriate use of vector methods

That's exactly right. The empty-buffer case was handled in #590.

@joe-maley joe-maley merged commit 9e5cfa8 into dev May 24, 2021
@joe-maley joe-maley deleted the eh/ch-7668 branch May 24, 2021 11:22
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.

debug build unit test failure "C++ API: Incorrect buffer size and offsets", crtl assert
3 participants