< prev index next >

src/share/vm/logging/log.hpp

Print this page
rev 9824 : [mq]: fixout
rev 9825 : imported patch log_copyright

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -118,19 +118,21 @@
 
   template <LogLevelType Level>
   ATTRIBUTE_PRINTF(1, 0)
   static void vwrite(const char* fmt, va_list args) {
     char buf[LogBufferSize];
+    va_list saved_args;         // For re-format on buf overflow.
+    va_copy(saved_args, args);
     size_t prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(buf, sizeof(buf));
     // Check that string fits in buffer; resize buffer if necessary
     int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
     assert(ret >= 0, "Log message buffer issue");
-    if ((size_t)ret > sizeof(buf)) {
+    if ((size_t)ret >= sizeof(buf)) {
       size_t newbuf_len = prefix_len + ret + 1;
       char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
       prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(newbuf, newbuf_len);
-      ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, args);
+      ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
       assert(ret >= 0, "Log message buffer issue");
       puts<Level>(newbuf);
       FREE_C_HEAP_ARRAY(char, newbuf);
     } else {
       puts<Level>(buf);
< prev index next >