Fix deserialization of maps into non-empty maps - #340
Merged
MiguelCompany merged 3 commits intoSep 7, 2026
Conversation
Tests added for both primitive and non-primitive mapped types: - Deserialization into a non-empty map. - Reuse of the same target map in two consecutive deserializations. - Content of the target map preserved when the deserialization fails. These tests show the issues described in eProsima#339. Signed-off-by: lijiapei <l2249712344@gmail.com>
Deserialize into a new map and move it into the output one once the whole deserialization succeeds. This way the output map is not left cleared or partially filled when an exception is thrown inside the deserialization loop, and the previous content of a non-empty output map is always replaced. This applies to both the primitive and non-primitive mapped type overloads. Fixes eProsima#339. Signed-off-by: lijiapei <l2249712344@gmail.com>
Contributor
Author
MiguelCompany
self-requested a review
September 7, 2026 06:59
Use explicit static_cast<uint16_t> for map keys, as done in DeserializeIntoANonEmptyMapInXCDRv1. int literals converted to uint16_t trigger warning C4244, treated as error by Windows CI. Signed-off-by: lijiapei <l2249712344@gmail.com>
shashenli
force-pushed
the
fix-339-map-deserialization
branch
from
September 7, 2026 07:46
03fe9f6 to
97b119c
Compare
Contributor
Author
|
Hi @MiguelCompany, The Windows CI failure was caused by the tests added in this PR: MSVC raises warning C4244 ( Fixed in 97b119c by using Since the CI workflows only trigger on |
MiguelCompany
requested review from
MiguelCompany
and removed request for
MiguelCompany
September 7, 2026 08:10
MiguelCompany
approved these changes
Sep 7, 2026
Member
|
@shashenli Thank you for your contribution! |
Member
|
@Mergifyio backport 2.3.x 2.2.x |
✅ Backports have been createdDetails
|
This was referenced Sep 7, 2026
MiguelCompany
pushed a commit
that referenced
this pull request
Sep 7, 2026
* Add tests for deserialization of maps into non-empty maps Tests added for both primitive and non-primitive mapped types: - Deserialization into a non-empty map. - Reuse of the same target map in two consecutive deserializations. - Content of the target map preserved when the deserialization fails. These tests show the issues described in #339. * Fix deserialization of maps into non-empty maps Deserialize into a new map and move it into the output one once the whole deserialization succeeds. This way the output map is not left cleared or partially filled when an exception is thrown inside the deserialization loop, and the previous content of a non-empty output map is always replaced. This applies to both the primitive and non-primitive mapped type overloads. Fixes #339. * Fix MSVC C4244 warning in map deserialization tests Use explicit static_cast<uint16_t> for map keys, as done in DeserializeIntoANonEmptyMapInXCDRv1. int literals converted to uint16_t trigger warning C4244, treated as error by Windows CI. --------- (cherry picked from commit b2457c4) Signed-off-by: lijiapei <l2249712344@gmail.com> Co-authored-by: lijiapei <lilingjie@cvte.com>
MiguelCompany
pushed a commit
that referenced
this pull request
Sep 7, 2026
* Add tests for deserialization of maps into non-empty maps Tests added for both primitive and non-primitive mapped types: - Deserialization into a non-empty map. - Reuse of the same target map in two consecutive deserializations. - Content of the target map preserved when the deserialization fails. These tests show the issues described in #339. * Fix deserialization of maps into non-empty maps Deserialize into a new map and move it into the output one once the whole deserialization succeeds. This way the output map is not left cleared or partially filled when an exception is thrown inside the deserialization loop, and the previous content of a non-empty output map is always replaced. This applies to both the primitive and non-primitive mapped type overloads. Fixes #339. * Fix MSVC C4244 warning in map deserialization tests Use explicit static_cast<uint16_t> for map keys, as done in DeserializeIntoANonEmptyMapInXCDRv1. int literals converted to uint16_t trigger warning C4244, treated as error by Windows CI. --------- (cherry picked from commit b2457c4) Signed-off-by: lijiapei <l2249712344@gmail.com> Co-authored-by: lijiapei <lilingjie@cvte.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
As reported in #339,
Cdr::deserialize(std::map<K, T>&)presents two problems when the output map is not empty:DataReader::take_next_sample()) silently kept stale keys and values.NotEnoughMemoryExceptionthrown inside the loop left the output map cleared or partially filled.Following the suggestion in #339, both overloads now deserialize the elements into a new map, which is moved into the output one once the whole deserialization succeeds. This way the previous content of the output map is always replaced, and it is preserved if the deserialization fails.
Two commits:
@Mergifyio backport 2.3.x
Fixes #339
Contributor Checklist
versions.mdfile (if applicable). Bug fix, no new feature.2.3.xis affected (reported against 2.3.6).Reviewer Checklist