Skip to content

Commit 5815b57

Browse files
committed
fix possible null-pointer dereference
1 parent 917debc commit 5815b57

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

cucumber_cpp/library/formatter/helper/TestCaseAttemptParser.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "cucumber_cpp/library/formatter/helper/TestCaseAttemptParser.hpp"
22
#include "cucumber/messages/attachment.hpp"
33
#include "cucumber/messages/pickle_step.hpp"
4-
#include "cucumber/messages/pickle_step_argument.hpp"
5-
#include "cucumber/messages/step_keyword_type.hpp"
64
#include "cucumber/messages/test_step.hpp"
75
#include "cucumber/messages/test_step_result.hpp"
86
#include "cucumber_cpp/library/formatter/helper/EventDataCollector.hpp"
@@ -12,6 +10,7 @@
1210
#include "cucumber_cpp/library/support/SupportCodeLibrary.hpp"
1311
#include <filesystem>
1412
#include <format>
13+
#include <map>
1514
#include <optional>
1615
#include <span>
1716
#include <string>
@@ -26,14 +25,13 @@ namespace cucumber_cpp::library::formatter::helper
2625
const GherkinStepMap& gherkinStepMap,
2726
std::string_view keyword,
2827
KeywordType keywordType,
29-
const cucumber::messages::pickle_step& pickleStep,
28+
const std::map<std::string, const cucumber::messages::pickle_step&>& pickleStepMap,
3029
std::filesystem::path pickleUri,
3130
support::SupportCodeLibrary supportCode,
3231
const cucumber::messages::test_step& testStep,
3332
const cucumber::messages::test_step_result& testStepResult,
3433
std::span<const cucumber::messages::attachment> attachments)
3534
{
36-
using std::operator""sv;
3735
ParsedTestStep parsedTestStep{
3836
.attachments = attachments,
3937
.keyword = std::string{ testStep.pickle_step_id ? keyword : (isBeforeHook ? "Before" : "After") },
@@ -61,6 +59,8 @@ namespace cucumber_cpp::library::formatter::helper
6159

6260
if (testStep.pickle_step_id)
6361
{
62+
const auto& pickleStep = pickleStepMap.at(*testStep.pickle_step_id);
63+
6464
parsedTestStep.location = {
6565
.uri = pickleUri.string(),
6666
.line = gherkinStepMap.at(pickleStep.ast_node_ids.front()).location.line
@@ -109,21 +109,20 @@ namespace cucumber_cpp::library::formatter::helper
109109
const auto& testStepResult = testCaseAttempt.stepResults.at(testStep.id);
110110
isBeforeHook = isBeforeHook && testStep.hook_id.has_value();
111111

112-
std::string_view keyword;
113-
KeywordType keywordType;
114-
const cucumber::messages::pickle_step* pickleStep{ nullptr };
112+
std::string_view keyword{};
113+
KeywordType keywordType{};
115114
if (testStep.pickle_step_id)
116115
{
117-
pickleStep = &pickleStepMap.at(*testStep.pickle_step_id);
118-
keyword = GetStepKeyword(*pickleStep, gherkinStepMap);
116+
const auto& pickleStep = pickleStepMap.at(*testStep.pickle_step_id);
117+
keyword = GetStepKeyword(pickleStep, gherkinStepMap);
119118
keywordType = GetStepKeywordType(keyword, gherkinDocument.feature->language, previousKeyWordType);
120119
}
121120

122121
parsedTestSteps.emplace_back(ParseStep(isBeforeHook,
123122
gherkinStepMap,
124123
keyword,
125124
keywordType,
126-
*pickleStep,
125+
pickleStepMap,
127126
relativePickleUri,
128127
supportCodeLibrary,
129128
testStep,

0 commit comments

Comments
 (0)