List:Commits« Previous MessageNext Message »
From:jack andrews Date:July 15 2009 7:54am
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-15
      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-15 07:52:30 +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;
@@ -619,6 +620,19 @@ TAPTEST(BaseString)
     OK(s4.assign((const char*)NULL).c_str() == NULL);
     OK(s4.assign(s4).c_str() == NULL);
 
+    //tests for Bug #45733 Cluster with more than 4 storage node 
+    for(int i=0;i<20;i++) 
+    {
+      OK(s2.assfmt("%*s",8,"Z"));
+      OK(s2.assfmt("%*s",511,"Z"));
+      OK(s2.assfmt("%*s",512,"Z"));
+      OK(s2.assfmt("%*s",513,"Z"));
+      OK(s2.assfmt("%*s",1023,"Z"));
+      OK(s2.assfmt("%*s",1024,"Z"));
+      OK(s2.assfmt("%*s",1025,"Z"));
+      OK(s2.assfmt("%*s",20*1024*1024,"Z"));
+    }
+
     return 1; // OK
 }
 

=== 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-15 07:52:30 +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,48 @@ 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 || ret >= size)
+  {
+    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 && ret < size)
+    return ret;
+#ifdef _WIN32
+  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;
+  {
+    char buf[512];
+    ret = vsnprintf(buf, sizeof(buf), format, ap);
+    if (ret >= 0 && ret < size)
+      return ret;
+    ret = vsnprintf_doubling(sizeof(buf), format, ap);
   }
+#endif
+  return ret;
 }


Attachment: [text/bzr-bundle] bzr/jack@sun.com-20090715075230-2jgxg83xaztsvp5v.bundle
Thread
bzr commit into mysql-5.1-telco-7.0 branch (jack:2948) Bug#45733jack andrews15 Jul
  • Re: bzr commit into mysql-5.1-telco-7.0 branch (jack:2948) Bug#45733Magnus BlĂ„udd15 Jul