Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Fix ReadFromBuffer() for empty strings in debug mode #12

Merged

Conversation

meyerj
Copy link
Contributor

@meyerj meyerj commented Oct 18, 2021

If the string to be read is empty (string_size == 0) and the package that includes this header is compiled in debug mode, then this assertion in Span::operator[] can fail because buffer[offset] would access the span past its boundaries if this is the last element in the buffer.

I assume that the implementations of std::string::assign(buffer_ptr, string_size) ignore the buffer_ptr if string_size == 0, but better to handle this case separately...

Edit: Actually it is not an assertion and span.hpp defines its own macros for checking contracts and either throw exceptions or terminate, but the result is the same.

@meyerj meyerj changed the title Fix ReadFromBuffer() for empty strings in Debug mode Fix ReadFromBuffer() for empty strings in debug mode Oct 18, 2021
@facontidavide
Copy link
Owner

thanks for the fix.

I should port this to the parser in PlotJuggler, too.

@facontidavide facontidavide reopened this Oct 18, 2021
@facontidavide facontidavide merged commit 37cb15a into facontidavide:master Oct 18, 2021
@meyerj meyerj deleted the fix/parsing-of-empty-strings branch October 18, 2021 16:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants