List:Commits« Previous MessageNext Message »
From:jack andrews Date:July 14 2009 10:32am
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-14
      Bug #45733  	Cluster with more than 4 storage node 
        . fixed basestring_vsprintf so it will always return
          the posix defined retval for vsnprintf.
      
          if the buffer can't hold the output string, the
          function will return the space needed.  you need
          to provide a buffer one larger than the retval
          so the terminating null will be written.

    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-14 10:28:44 +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 == 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-14 10:28:44 +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,49 @@ basestring_snprintf(char *str, size_t si
   return(ret);
 }
 
-#ifdef SNPRINTF_RETURN_TRUNC
-static char basestring_vsnprintf_buf[16*1024];
-#endif
+int
+vsnprintf_doubling(size_t size, const char *format, va_list ap)
+{
+  char *buf = 0;
+  int ret = -1;
+
+  while (ret < 0)
+  {
+    buf = realloc(buf, size*=2);
+    ret = vsnprintf(buf, size, format, ap);
+  }
+  free(buf);
+  return ret;
+}
+
 int
 basestring_vsnprintf(char *str, size_t size, const char *format, va_list ap)
 {
+  int ret;
+
   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
+    return basestring_vsnprintf(buf, 1, format, ap);
   }
-  {
-    int ret= vsnprintf(str, size, format, ap);
+  ret = IF_WIN(_vsnprintf,vsnprintf)(str, size, format, ap);
+  if (ret >= 0)
+    return ret;
+#ifdef _WIN32
+  assert(ret < 0);
+  if (errno == EINVAL)
+    return ret;
+  // otherwise, more than size chars are needed
+  return _vscprintf(format, ap);
+#endif
 #ifdef SNPRINTF_RETURN_TRUNC
-    if (ret == size-1 || ret == -1)
-    {
-      ret= vsnprintf(basestring_vsnprintf_buf,
-		     sizeof(basestring_vsnprintf_buf),
-		     format, ap);
-    }
-#endif
-    return ret;
+  assert(ret < 0);
+  {
+    char buf[512];
+    ret = vsnprintf(buf, sizeof(buf), format, ap);
   }
+  if (ret < 0)
+    ret = vsnprintf_doubling(sizeof(buf), format, ap);
+  return ret;
+#endif
 }


Attachment: [text/bzr-bundle] bzr/jack@sun.com-20090714102844-48pad9twlmh523mm.bundle
Thread
bzr commit into mysql-5.1-telco-7.0 branch (jack:2948) Bug#45733jack andrews14 Jul