From: Pierre-Emmanuel Patry Date: Tue, 9 Dec 2025 05:52:13 +0000 (+0100) Subject: gccrs: Remove static buffer size and improve error message X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32bba8ee8fdb9fab698d809d78c190467edb36ee;p=thirdparty%2Fgcc.git gccrs: Remove static buffer size and improve error message gcc/rust/ChangeLog: * rust-session-manager.cc (Session::enable_dump): Rework error message and remove magic value. (Session::handle_excluded_node): Remove static buffer size. Signed-off-by: Pierre-Emmanuel Patry --- diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index c948f3d1548..cf34e8f47d4 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -328,6 +328,8 @@ Session::handle_cfg_option (std::string &input) bool Session::enable_dump (std::string arg) { + const std::string INTERNAL_DUMP_OPTION_TEXT = "internal"; + if (arg.empty ()) { rust_error_at ( @@ -383,21 +385,23 @@ Session::enable_dump (std::string arg) { options.enable_dump_option (CompileOptions::BIR_DUMP); } - else if (!arg.compare (0, 8, "internal")) + else if (!arg.compare (0, INTERNAL_DUMP_OPTION_TEXT.size (), + INTERNAL_DUMP_OPTION_TEXT)) { - if (arg.size () == 8) + if (arg.size () == INTERNAL_DUMP_OPTION_TEXT.size ()) { options.enable_dump_option (CompileOptions::INTERNAL_DUMP); } else { - if (arg[8] != ':') + if (arg[INTERNAL_DUMP_OPTION_TEXT.size ()] != ':') { - rust_error_at (UNDEF_LOCATION, - "%qs malformated to specify Node to ignore when " - "dumping internal comment put a " - "%qs then all the Nodes separated by comma", - arg.c_str (), ":"); + rust_error_at (UNDEF_LOCATION, "bad format for %qs", + arg.c_str ()); + rust_inform (UNDEF_LOCATION, + "to specify the nodes to ignore when " + "dumping their description put a " + "%<:%> then all the Nodes separated by comma"); return false; } handle_excluded_node (arg); @@ -409,9 +413,9 @@ Session::enable_dump (std::string arg) rust_error_at ( UNDEF_LOCATION, "dump option %qs was unrecognised. choose %, %, " - "%, %, " - "%, %, %, %, " - "%, or %", + "%, %, " + "%, %, %, %, " + "%, %, or %", arg.c_str ()); return false; } @@ -424,9 +428,9 @@ Session::enable_dump (std::string arg) void Session::handle_excluded_node (std::string arg) { - const int size_node_string = 50; - std::istringstream blist_str ( - arg.substr (arg.find (":") + 1, size_node_string)); + size_t colon = arg.find (":"); + size_t suffix_size = arg.size () - colon; + std::istringstream blist_str (arg.substr (colon + 1, suffix_size)); std::string token; while (std::getline (blist_str, token, ',')) {