]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: remove incorrect use of std::includes() 47570/head
authorIlya Dryomov <idryomov@gmail.com>
Fri, 12 Aug 2022 09:10:45 +0000 (11:10 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 12 Aug 2022 09:10:45 +0000 (11:10 +0200)
- std::includes() requires sorted ranges but command specs aren't
  sorted
- std::includes() purpose is to check whether the second range is
  a subsequence of the first range but here the size of the second
  range is always equal to the size of the first range, which means
  that, had the ranges been sorted, std::includes() would have checked
  straight equality

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
src/tools/rbd/Shell.cc

index 2095682654430250852be4769269dfaec917f707..ab1d203311e9fb5bedb232d4afe2d485b0b1d5bd 100644 (file)
@@ -310,10 +310,9 @@ Shell::Action *Shell::find_action(const CommandSpec &command_spec,
 
   for (Action *action : actions) {
     if (action->command_spec.size() <= command_spec.size()) {
-      if (std::includes(action->command_spec.begin(),
-                        action->command_spec.end(),
-                        command_spec.begin(),
-                        command_spec.begin() + action->command_spec.size())) {
+      if (std::equal(action->command_spec.begin(),
+                     action->command_spec.end(),
+                     command_spec.begin())) {
         if (matching_spec != NULL) {
           *matching_spec = &action->command_spec;
         }
@@ -323,11 +322,9 @@ Shell::Action *Shell::find_action(const CommandSpec &command_spec,
     }
     if (!action->alias_command_spec.empty() &&
         action->alias_command_spec.size() <= command_spec.size()) {
-      if (std::includes(action->alias_command_spec.begin(),
-                        action->alias_command_spec.end(),
-                        command_spec.begin(),
-                        command_spec.begin() +
-                          action->alias_command_spec.size())) {
+      if (std::equal(action->alias_command_spec.begin(),
+                     action->alias_command_spec.end(),
+                     command_spec.begin())) {
         if (matching_spec != NULL) {
           *matching_spec = &action->alias_command_spec;
         }