More strcpy() strcat() sprintf() squashing
[fw/sdcc] / src / SDCCmacro.c
index ec961f99adf1b95d5eef55e45356d00e5846a289..9691c0bdce6d5f5f1d879feabddd69f6fc0a3d06 100644 (file)
@@ -116,7 +116,24 @@ mvsprintf(hTab *pvals, const char *pformat, va_list ap)
   /* Recursivly evaluate all the macros in the string */
   _evalMacros(ainto, pvals, pformat, MAX_STRING_LENGTH);
   /* Evaluate all the arguments */
-  vsprintf(atmp, ainto, ap);
+#if defined(HAVE_VSNPRINTF)
+    if (vsnprintf(atmp, MAX_STRING_LENGTH, ainto, ap) >= MAX_STRING_LENGTH)
+    {
+       fprintf(stderr, "Internal error: mvsprintf output truncated.\n");
+    }
+#else    
+    {  
+       int wlen; 
+       
+       wlen = vsprintf(atmp, ainto, ap);
+       
+       if (wlen < 0 || wlen >= MAX_STRING_LENGTH)
+       {
+           wassertl(0, "mvsprintf overflowed.");
+       }
+    }
+#endif    
+    
   /* Recursivly evaluate any macros that were used as arguments */
   _evalMacros(ainto, pvals, atmp, MAX_STRING_LENGTH);