List:Commits« Previous MessageNext Message »
From:jack andrews Date:July 13 2009 10:03am
Subject:bzr commit into mysql-5.1-telco-7.0 branch (jack:2948) Bug#45733
View as plain text  
#At file:///D:/repo/more-than-4-ndbd-bug45733/ based on revid:jonas@stripped

 2948 jack andrews	2009-07-13
      Bug #45733  	Cluster with more than 4 storage node 
        . fixed basestring_vsnprintf on windows

    modified:
      storage/ndb/src/common/util/BaseString.cpp
      storage/ndb/src/common/util/basestring_vsnprintf.c
=== modified file 'storage/ndb/src/common/util/BaseString.cpp'
--- a/storage/ndb/src/common/util/BaseString.cpp	2009-06-06 12:52:24 +0000
+++ b/storage/ndb/src/common/util/BaseString.cpp	2009-07-13 10:02:22 +0000
@@ -210,7 +210,8 @@ BaseString::assfmt(const char *fmt, ...)
 	m_chr = t;
     }
     va_start(ap, fmt);
-    basestring_vsnprintf(m_chr, l, fmt, ap);
+    l = basestring_vsnprintf(m_chr, l, fmt, ap);
+    assert(l<=(int)strlen(m_chr));
     va_end(ap);
     m_len = strlen(m_chr);
     return *this;

=== modified file 'storage/ndb/src/common/util/basestring_vsnprintf.c'
--- a/storage/ndb/src/common/util/basestring_vsnprintf.c	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/src/common/util/basestring_vsnprintf.c	2009-07-13 10:02:22 +0000
@@ -24,12 +24,6 @@
 #include <basestring_vsnprintf.h>
 #include <my_global.h>
 
-#ifdef _WINDOWS
-#define SNPRINTF_RETURN_TRUNC
-#define snprintf _snprintf
-#define vsnprintf _vsnprintf
-#endif
-
 int
 basestring_snprintf(char *str, size_t size, const char *format, ...)
 {
@@ -41,33 +35,38 @@ basestring_snprintf(char *str, size_t si
   return(ret);
 }
 
-#ifdef SNPRINTF_RETURN_TRUNC
-static char basestring_vsnprintf_buf[16*1024];
+int correct_vsnprintf_return_value(char *str, size_t size, const char *format, va_list ap, int ret)
+{
+  static size_t buffer_size = 128;
+  static char *growing_buffer = 0;
+#ifdef _WIN32
+  if (ret == size)
+    return size+1;
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
+  if (ret == -1)
+  {
+    if(!growing_buffer)
+      growing_buffer = malloc(buffer_size);
+    while (ret == -1) {
+      ret = vsnprintf(growing_buffer, buffer_size, format, ap);
+      if(ret == -1)
+        growing_buffer = realloc(growing_buffer,buffer_size*=2);
+    }
+  }
 #endif
+  return ret;
+}
+
 int
 basestring_vsnprintf(char *str, size_t size, const char *format, va_list ap)
 {
+  int ret = -1;
   if (size == 0)
   {
-#ifdef SNPRINTF_RETURN_TRUNC
-    return vsnprintf(basestring_vsnprintf_buf,
-		     sizeof(basestring_vsnprintf_buf),
-		     format, ap);
-#else
     char buf[1];
-    return vsnprintf(buf, 1, format, ap);
-#endif
-  }
-  {
-    int ret= vsnprintf(str, size, format, ap);
-#ifdef SNPRINTF_RETURN_TRUNC
-    if (ret == size-1 || ret == -1)
-    {
-      ret= vsnprintf(basestring_vsnprintf_buf,
-		     sizeof(basestring_vsnprintf_buf),
-		     format, ap);
-    }
-#endif
-    return ret;
+    return basestring_vsnprintf(buf, 1, format, ap);
   }
+  ret = vsnprintf(str, size, format, ap);
+  return correct_vsnprintf_return_value(str, size, format, ap, ret);
 }


Attachment: [text/bzr-bundle] bzr/jack@sun.com-20090713100222-424rjwp2x7wmuuc7.bundle
Thread
bzr commit into mysql-5.1-telco-7.0 branch (jack:2948) Bug#45733jack andrews13 Jul