]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw_kms: fix concat_url for empty url case 32387/head
authorSamuel Just <sjust@redhat.com>
Sat, 21 Dec 2019 02:11:58 +0000 (02:11 +0000)
committerSamuel Just <sjust@redhat.com>
Thu, 23 Jan 2020 00:03:14 +0000 (16:03 -0800)
Can't call back() on an empty string.  Causes unittest_rgw_kms
to fail when compiled with _GLIBCXX_ASSERTIONS.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/rgw/rgw_kms.cc

index 098edeca51bddcdff31dbd5f9e739c5d6cde3f52..dd6ba062d08dda7a4f82d80bfff2381cc96282fb 100644 (file)
@@ -25,10 +25,11 @@ using namespace rgw;
  * empty, the URL is not changed.
  */
 static void concat_url(std::string &url, std::string path) {
+  bool url_has_slash = !url.empty() && url.back() == '/';
   if (!path.empty()) {
-    if (url.back() == '/' && path.front() == '/') {
+    if (url_has_slash && path.front() == '/') {
       url.pop_back();
-    } else if (url.back() != '/' && path.front() != '/') {
+    } else if (!url_has_slash && path.front() != '/') {
       url.push_back('/');
     }
     url.append(path);