Skip to content

Commit 2095256

Browse files
committed
fixup: benchdnn: parser: check for dangling symbol at get_substr
Parsing values for two global objects in a single function must be done carefully.
1 parent 8db2ef0 commit 2095256

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/benchdnn/utils/parser.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -1025,13 +1025,26 @@ static bool parse_engine(
10251025
"`cpu` or `gpu`.\n `INDEX` is an integer value specifying "
10261026
"which engine to use if several were identified.\n";
10271027

1028+
// Note: this is a special case because index and engine kind are parsed
1029+
// into separate global objects instead of one under a common parsing
1030+
// function.
1031+
// TODO: fix this.
1032+
//
1033+
// Because of this fact, need to extract kind separated by `:`. `:` can be
1034+
// valid dangling for certain options in the command line (--strides=::).
1035+
// Thus, extract the kind allowing dangling. Verify, it's `--engine` option,
1036+
// and if yes, perform a safe check for dangling after.
10281037
size_t start_pos = 0;
1029-
std::string kind_str = get_substr(str, start_pos, ':');
1038+
std::string kind_str = get_substr(str, start_pos, ':', true);
10301039

10311040
if (!parse_single_value_option(engine_tgt_kind, dnnl_cpu, str2engine_kind,
10321041
kind_str.c_str(), option_name, help))
10331042
return false;
10341043

1044+
// This is to catch a dangling `:` at the end of `--engine`.
1045+
start_pos = 0;
1046+
kind_str = get_substr(str, start_pos, ':');
1047+
10351048
if (start_pos != std::string::npos) {
10361049
std::string index_str(str + start_pos);
10371050
// If the index is a valid number, let the library catch potential

0 commit comments

Comments
 (0)