-
Notifications
You must be signed in to change notification settings - Fork 337
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
Invalid memory access when calling transform(vector_2d, fn)
with heterogeneous vector
#431
Comments
transform(vector_2d, fn)
with heterogeneous vector
Yes, that's true. I don't know if there's something we can do about it. I never considered this possibility. If not, it could be a precondition for the function to be asserted in debug mode. |
Yes. That's a bug. Macros are case-sensitive. |
Just so I understand (still learning), if the user is building in debug mode the library would run input checks?
Yeah, I'm not sure what the best fix is that wouldn't introduce potentially-costly checks; refactors; or additional dependencies like Eigen. I don't see why a user would pass in non-uniform data in an actual use-case, but maybe a documentation note specifying that the functions expect uniformly-dimensioned input would work as a short-term remedy?
Good to know, thank you. |
Yes. If they're cheap.
Yes. The pre-conditions should be documented. Although we only have comments for now. There's no library reference in the documentation. |
Bug category
Describe the bug
Hello, while studying
matplot/util/common.cpp
, I noticed that the implementation fortransform
derives the number of columns based on the number of columns in the first row of a 2D vector. This results in access violations when calling the function with a vector in which any subsequent row has less thanx[0].size()
elements (see example below).Similarly, I think this issue also presents itself in
flatten
because ifx[0].size()
happens to be smaller than any other row, the output vector's reserved size will be too small, requiring reallocation during the insert operation. This reallocation would render the iterators invalid (if I understood std::vector::insert correctly).Steps to Reproduce
Compile and run these tests:
Test 1: Non-empty Rows
Output
Test 2: Empty Rows
Output
Segmentation fault (core dumped)
Platform
Environment Details:
Additional context
I am aware that most users would pass in homogeneously-dimensioned vectors to the API, but I wanted to test to see if the potential violation was there. I don't know whether the library's perspective is to assume users wouldn't do that or to ensure they won't, so I decided to report it just in case.
P.S.
Not really the subject of the report, but I also noticed an inconsistency of capitalization on
_TEMP_MACRO_
on line 248 ofcommon.cpp
when compared to lines 227, 250, and 252. I don't know if macros are case-sensitive or not, so I'm just noting it here.The text was updated successfully, but these errors were encountered: