diff options
| author | saturneric <[email protected]> | 2026-09-22 22:36:00 +0200 |
|---|---|---|
| committer | saturneric <[email protected]> | 2026-09-22 22:36:00 +0200 |
| commit | e33e0937ac2b5fd4052bd091e9a7d620871a6a32 (patch) | |
| tree | 6c92777865f95f914039cf285854ab055b422377 /src/m_pgp_inspect/test/PGPInspectModelTest.cpp | |
| parent | style(key-server-sync): normalize text punctuation (diff) | |
| download | modules-e33e0937ac2b5fd4052bd091e9a7d620871a6a32.tar.gz modules-e33e0937ac2b5fd4052bd091e9a7d620871a6a32.zip | |
fix(pgp-inspect): preserve parsed document lifetime
- store parsed documents before referencing their packets
- prevent dangling references caused by temporary documents
- clarify packet summary test ownership with an explanatory comment
Diffstat (limited to 'src/m_pgp_inspect/test/PGPInspectModelTest.cpp')
| -rw-r--r-- | src/m_pgp_inspect/test/PGPInspectModelTest.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/m_pgp_inspect/test/PGPInspectModelTest.cpp b/src/m_pgp_inspect/test/PGPInspectModelTest.cpp index 3815176..f76d559 100644 --- a/src/m_pgp_inspect/test/PGPInspectModelTest.cpp +++ b/src/m_pgp_inspect/test/PGPInspectModelTest.cpp @@ -123,8 +123,8 @@ TEST(PGPInspectModelTest, CountsNestedPacketsToo) { } TEST(PGPInspectModelTest, KeepsTheFramingFiguresVerbatim) { - const auto& packet = - ParsePGPInspectDocument(kDocument).blocks.at(0).packets.at(0); + const auto document = ParsePGPInspectDocument(kDocument); + const auto& packet = document.blocks.at(0).packets.at(0); EXPECT_EQ(packet.offset, 0); EXPECT_EQ(packet.header_length, 2); @@ -136,8 +136,8 @@ TEST(PGPInspectModelTest, KeepsTheFramingFiguresVerbatim) { TEST(PGPInspectModelTest, AbsentVersionReadsAsMinusOne) { // Most container packets carry no version octet. That is a fact about the // type, so it must not look like a defect in the document. - const auto& packet = - ParsePGPInspectDocument(kDocument).blocks.at(0).packets.at(0); + const auto document = ParsePGPInspectDocument(kDocument); + const auto& packet = document.blocks.at(0).packets.at(0); EXPECT_EQ(packet.version, -1); EXPECT_FALSE(packet.Malformed()); } @@ -252,9 +252,10 @@ TEST(PGPInspectModelTest, ANestedPacketAloneIsStructureEnough) { // -- the summaries the tree shows --------------------------------------------- TEST(PGPInspectModelTest, APacketSummaryNamesTagVersionOffsetAndSize) { - const auto& packet = - ParsePGPInspectDocument(kDocument).blocks.at(0).packets.at(0).children.at( - 0); + // Held by value: a reference into the temporary document would dangle as + // soon as this statement ends. + const auto document = ParsePGPInspectDocument(kDocument); + const auto& packet = document.blocks.at(0).packets.at(0).children.at(0); const auto summary = PGPInspectPacketSummary(packet, 1); EXPECT_TRUE(summary.contains("#1")); |
