ncurses 5.9 - patch 20121026
[ncurses.git] / ncurses / trace / varargs.c
index f4ee46710abb74d347ace47536f71e9d6235e26b..66252d88db210834c12a1fcc972592e3b0370472 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc.              *
+ * Copyright (c) 2001-2008,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -34,7 +34,7 @@
 
 #include <ctype.h>
 
-MODULE_ID("$Id: varargs.c,v 1.7 2008/08/03 15:42:49 tom Exp $")
+MODULE_ID("$Id: varargs.c,v 1.11 2012/10/27 21:03:28 tom Exp $")
 
 #ifdef TRACE
 
@@ -44,7 +44,7 @@ typedef enum {
     atUnknown = 0, atInteger, atFloat, atPoint, atString
 } ARGTYPE;
 
-#define VA_INT(type) ival = va_arg(ap, type)
+#define VA_INT(type) ival = (int) va_arg(ap, type)
 #define VA_FLT(type) fval = va_arg(ap, type)
 #define VA_PTR(type) pval = (char *)va_arg(ap, type)
 #define VA_STR(type) sval = va_arg(ap, type)
@@ -149,25 +149,32 @@ _nc_varargs(const char *fmt, va_list ap)
                        param = buffer;
                        switch (used) {
                        case atInteger:
-                           sprintf(buffer, "%d", ival);
+                           _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+                                       "%d", ival);
                            break;
                        case atFloat:
-                           sprintf(buffer, "%f", fval);
+                           _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+                                       "%f", fval);
                            break;
                        case atPoint:
-                           sprintf(buffer, "%p", pval);
+                           _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+                                       "%p", pval);
                            break;
                        case atString:
                            param = _nc_visbuf2(1, sval);
                            break;
                        case atUnknown:
                        default:
-                           strcpy(buffer, "?");
+                           _nc_STRCPY(buffer, "?", sizeof(buffer));
                            break;
                        }
                        MyLength += strlen(param) + 2;
                        MyBuffer = typeRealloc(char, MyLength, MyBuffer);
-                       sprintf(MyBuffer + strlen(MyBuffer), ", %s", param);
+                       if (MyBuffer != 0) {
+                           _nc_SPRINTF(MyBuffer + strlen(MyBuffer),
+                                       _nc_SLIMIT(MyLength - strlen(MyBuffer))
+                                       ", %s", param);
+                       }
                    }
                }
                used = atUnknown;
@@ -177,7 +184,7 @@ _nc_varargs(const char *fmt, va_list ap)
        }
     }
 
-    return (MyBuffer);
+    return (MyBuffer ? MyBuffer : dummy);
 }
 #else
 EMPTY_MODULE(_nc_varargs)