allow command to accept "--" separator
[folly.git] / folly / experimental / StringKeyedCommon.h
index f6816c9d8d9cd44cf669e179cb37028b0be95e84..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.
 // Copyright 2013-present Facebook. All Rights Reserved.
 // @author: Pavlo Kushnir (pavlo)
 
-#ifndef FOLLY_EXPERIMENTAL_STRINGKEYEDCOMMON_H_
-#define FOLLY_EXPERIMENTAL_STRINGKEYEDCOMMON_H_
+#pragma once
 
 #include <memory>
+
 #include <folly/Range.h>
 
 namespace folly {
@@ -29,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);
 }
 
@@ -39,6 +42,4 @@ void stringPieceDel(StringPiece piece, const Alloc& alloc) {
     .deallocate(const_cast<char*>(piece.data()), piece.size());
 }
 
-} // folly
-
-#endif /* FOLLY_EXPERIMENTAL_STRINGKEYEDCOMMON_H_ */
+} // namespace folly