Skip to content

Commit c911956

Browse files
committed
Cleanup: Use const and proper indexing in do_comp_args
do_comp_args() got the name in the args and then used args starting from 1. Instead, remove command and name before call and start from 0.
1 parent 6c23c1e commit c911956

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/rtapi/uspace_rtapi_main.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,15 @@ static int do_one_item(
161161
return 0;
162162
}
163163

164-
static void remove_quotes(std::string &s) {
165-
s.erase(remove_copy(s.begin(), s.end(), s.begin(), '"'), s.end());
164+
static std::string remove_quotes(const std::string &s) {
165+
std::string ret;
166+
std::remove_copy(s.begin(), s.end(), std::back_inserter(ret), '"');
167+
return ret;
166168
}
167169

168-
static int do_comp_args(void *module, std::vector<std::string> args) {
169-
for (unsigned i = 1; i < args.size(); i++) {
170-
std::string &s = args[i];
171-
remove_quotes(s);
170+
static int do_comp_args(void *module, const std::vector<std::string> &args) {
171+
for (unsigned i = 0; i < args.size(); i++) {
172+
std::string s = remove_quotes(args[i]);
172173
size_t idx = s.find('=');
173174
if (idx == std::string::npos) {
174175
rtapi_print_msg(RTAPI_MSG_ERR, "Invalid parameter `%s'\n", s.c_str());
@@ -513,7 +514,7 @@ static bool send_args(int fd, const std::vector<std::string> &args) {
513514
return true;
514515
}
515516

516-
static int handle_command(std::vector<std::string> args) {
517+
static int handle_command(const std::vector<std::string> &args) {
517518
if (args.size() == 0) {
518519
return 0;
519520
}
@@ -522,8 +523,8 @@ static int handle_command(std::vector<std::string> args) {
522523
return 0;
523524
} else if (args.size() >= 2 && args[0] == "load") {
524525
std::string name = args[1];
525-
args.erase(args.begin());
526-
return do_load_cmd(name, args);
526+
std::vector<std::string> args_rem(args.begin() + 2, args.end());
527+
return do_load_cmd(name, args_rem);
527528
} else if (args.size() == 2 && args[0] == "unload") {
528529
return do_unload_cmd(args[1]);
529530
} else if (args.size() == 3 && args[0] == "newinst") {

0 commit comments

Comments
 (0)