From: Changgyu Choi Date: Tue, 17 Jan 2023 07:16:54 +0000 (+0900) Subject: Fix invalid access X-Git-Tag: accepted/tizen/unified/20230420.153149~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=960178e7ce075261211282224a85408a0d2a4de7;p=platform%2Fcore%2Fappfw%2Ftidl.git Fix invalid access If std::string.length() is zero, then back() method's behavior is undefined. Change-Id: I5ccededf83b76058e91ebefec6b11ad8ff8f1db6 Signed-off-by: Changgyu Choi --- diff --git a/idlc/gen/c_gen_base.cc b/idlc/gen/c_gen_base.cc index 0480a6e..df2ac1a 100644 --- a/idlc/gen/c_gen_base.cc +++ b/idlc/gen/c_gen_base.cc @@ -232,7 +232,10 @@ std::string CGeneratorBase::SmartIndent(std::string lines) { tab_size--; } - back = line.back(); + back = "__INVALID__"; + if (line.length() > 0) + back = line.back(); + if (back != ":" && line.length() > 0) tab += Tab(tab_size); @@ -250,9 +253,7 @@ std::string CGeneratorBase::SmartIndent(std::string lines) { if (back == "," || back == "\\") continuous = true; - if (line.empty() || - line.length() == 0 || - std::all_of(line.begin(), line.end(), isspace)) { + if (line.empty() || std::all_of(line.begin(), line.end(), isspace)) { std::string n_line = Trim(next_line); if (n_line.empty() || n_line.length() == 0 || @@ -296,7 +297,6 @@ std::string CGeneratorBase::SmartIndent(std::string lines) { if_statement = true; } - back = line.back(); found = line.find("while ("); if (found != std::string::npos && back != ";") { tab_size++; diff --git a/idlc/gen/dart_gen_base.cc b/idlc/gen/dart_gen_base.cc index 008b5c7..4403bfc 100644 --- a/idlc/gen/dart_gen_base.cc +++ b/idlc/gen/dart_gen_base.cc @@ -507,7 +507,10 @@ std::string DartGeneratorBase::SmartIndent(std::string lines) { tab += Tab(2); // Checks whether switch case is end or not. - line_back = line.back(); + line_back = "__INVALID__"; + if (line.length() > 0) + line_back = line.back(); + if (!prev_tab_size.empty() && prev_tab_size.top() == (tab_size - 1) && line_back == "}") { prev_tab_size.pop(); diff --git a/idlc/gen_cion/c_cion_gen_base.cc b/idlc/gen_cion/c_cion_gen_base.cc index 85d9590..78e9317 100644 --- a/idlc/gen_cion/c_cion_gen_base.cc +++ b/idlc/gen_cion/c_cion_gen_base.cc @@ -231,7 +231,10 @@ std::string CCionGeneratorBase::SmartIndent(std::string lines) { tab_size--; } - back = line.back(); + back = "__INVALID__"; + if (line.length() > 0) + back = line.back(); + if (back != ":" && line.length() > 0) tab += Tab(tab_size); @@ -249,9 +252,7 @@ std::string CCionGeneratorBase::SmartIndent(std::string lines) { if (back == "," || back == "\\") continuous = true; - if (line.empty() || - line.length() == 0 || - std::all_of(line.begin(), line.end(), isspace)) { + if (line.empty() || std::all_of(line.begin(), line.end(), isspace)) { std::string n_line = Trim(next_line); if (n_line.empty() || n_line.length() == 0 || @@ -295,7 +296,6 @@ std::string CCionGeneratorBase::SmartIndent(std::string lines) { if_statement = true; } - back = line.back(); found = line.find("while ("); if (found != std::string::npos && back != ";") { tab_size++;