Index: /issm/trunk-jpl/src/c/shared/Exceptions/exprintf.cpp
===================================================================
--- /issm/trunk-jpl/src/c/shared/Exceptions/exprintf.cpp	(revision 12459)
+++ /issm/trunk-jpl/src/c/shared/Exceptions/exprintf.cpp	(revision 12460)
@@ -9,4 +9,5 @@
 #include <stdarg.h>
 #include <stdio.h>
+#include "../Alloc/xNewDelete.h"
 #include "../Alloc/alloc.h"
 
@@ -14,17 +15,38 @@
 
 	/*returned string: */
-	char* string=NULL;
+	char *buffer = NULL;
+	int   n,size = 100;
+	int   string_size;
 
-	/*Assum nobody will print more that 1024 characters!*/
-	string=(char*)xmalloc(1024*sizeof(char));//assume that nobody will print more than 1024 characters at once.
-                                                                                                                                                                                                     
 	//variable list of arguments
-	va_list ap;
+	va_list args;
 
-	//First use vsprintf to get the whole input string.
-	va_start(ap,format);
-	vsprintf(string,format,ap); //printf style coding 
-	va_end(ap); 
+	while(true){
 
-	return string;
+		/*allocate buffer for given string size*/
+		//buffer=xNew<char>(size);
+		buffer=(char*)xmalloc(size*sizeof(char));
+
+		/* Try to print in the allocated space. */
+		va_start(args, format);
+#ifndef WIN32
+		n=vsnprintf(buffer,size,format,args);
+#else
+		n=vsnprintf(buffer,size,format,args);
+#endif
+		va_end(args);
+
+		/* If that worked, return the string. */
+		if(n>-1 && n<size) break;
+
+		/* Else try again with more space. */
+		if(n>-1)   /* glibc 2.1 */
+		 size=n+1; /* precisely what is needed */
+		else       /* glibc 2.0 */
+		 size*=2;  /* twice the old size */
+
+		xDelete<char>(buffer);
+	}
+
+	return buffer;
 }
