Add a SIGSEGV signal handler which detects stack overflow
[folly.git] / folly / Varint.h
index a9b9d0d6b63fb0c8f4744e20bc80dc113c6f8f92..e4af0c19000a02697f0d5aee3ad1711ff44791fb 100644 (file)
@@ -14,8 +14,7 @@
  * limitations under the License.
  */
 
-#ifndef FOLLY_VARINT_H_
-#define FOLLY_VARINT_H_
+#pragma once
 
 #include <type_traits>
 #include <folly/Conv.h>
@@ -72,7 +71,8 @@ uint64_t decodeVarint(Range<T*>& data);
 inline uint64_t encodeZigZag(int64_t val) {
   // Bit-twiddling magic stolen from the Google protocol buffer document;
   // val >> 63 is an arithmetic shift because val is signed
-  return static_cast<uint64_t>((val << 1) ^ (val >> 63));
+  auto uval = static_cast<uint64_t>(val);
+  return static_cast<uint64_t>((uval << 1) ^ (val >> 63));
 }
 
 inline int64_t decodeZigZag(uint64_t val) {
@@ -138,5 +138,3 @@ inline uint64_t decodeVarint(Range<T*>& data) {
 }
 
 }  // namespaces
-
-#endif /* FOLLY_VARINT_H_ */