$OpenBSD: patch-src_lib_json_json_writer_cpp,v 1.1 2016/01/20 09:37:13 dcoppa Exp $

commit 1b32e3e869059e437c43ba0f8765c3e5857801f7
Author: Michael Shields <mshields@google.com>
Date:   Mon Jul 27 16:35:19 2015 -0700

Fix cases where the most negative signed integer was negated, causing
undefined behavior.

--- src/lib_json/json_writer.cpp.orig	Thu Jul 23 07:32:47 2015
+++ src/lib_json/json_writer.cpp	Wed Jan 20 09:47:02 2016
@@ -71,12 +71,15 @@ static bool containsControlCharacter0(const char* str,
 std::string valueToString(LargestInt value) {
   UIntToStringBuffer buffer;
   char* current = buffer + sizeof(buffer);
-  bool isNegative = value < 0;
-  if (isNegative)
-    value = -value;
-  uintToString(LargestUInt(value), current);
-  if (isNegative)
+  if (value == Value::minLargestInt) {
+    uintToString(LargestUInt(Value::maxLargestInt) + 1, current);
     *--current = '-';
+  } else if (value < 0) {
+    uintToString(LargestUInt(-value), current);
+    *--current = '-';
+  } else {
+    uintToString(LargestUInt(value), current);
+  }
   assert(current >= buffer);
   return current;
 }
