allow command to accept "--" separator
[folly.git] / folly / experimental / StringKeyedCommon.h
index 26eed9efaced84a89419fa8d8af1b3c33621b09b..c281cb5b13fb3a0c7dcedb2f4695a4b645582440 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2015-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 #pragma once
 
 #include <memory>
+
 #include <folly/Range.h>
 
 namespace folly {
@@ -28,7 +29,10 @@ StringPiece stringPieceDup(StringPiece piece, const Alloc& alloc) {
   auto size = piece.size();
   auto keyDup = typename Alloc::template rebind<char>::other(alloc)
     .allocate(size);
-  memcpy(keyDup, piece.data(), size * sizeof(typename StringPiece::value_type));
+  if (size) {
+    memcpy(
+        keyDup, piece.data(), size * sizeof(typename StringPiece::value_type));
+  }
   return StringPiece(keyDup, size);
 }
 
@@ -38,4 +42,4 @@ void stringPieceDel(StringPiece piece, const Alloc& alloc) {
     .deallocate(const_cast<char*>(piece.data()), piece.size());
 }
 
-} // folly
+} // namespace folly