]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/safe_sprintf.c
ncurses 6.1 - patch 20180519
[ncurses.git] / ncurses / base / safe_sprintf.c
index 9cea066ca24c81f558a8aa52041bb6b65efc7e65..22db3ba7fde1c7617ce944cba30d5c1a7c863483 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2010,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2013,2018 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            *
  ****************************************************************************/
 
 /****************************************************************************
- *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
+ *  Author: Thomas E. Dickey        1997-on                                 *
  ****************************************************************************/
 
 #include <curses.priv.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: safe_sprintf.c,v 1.26 2012/02/22 22:40:24 tom Exp $")
+MODULE_ID("$Id: safe_sprintf.c,v 1.31 2018/02/17 21:19:41 tom Exp $")
 
 #if USE_SAFE_SPRINTF
 
@@ -114,6 +114,7 @@ _nc_printf_length(const char *fmt, va_list ap)
                                "%d", ival);
                    fmt_len += strlen(fmt_arg);
                    if ((format = _nc_doalloc(format, fmt_len)) == 0) {
+                       free(buffer);
                        return -1;
                    }
                    --f;
@@ -223,7 +224,7 @@ NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_DCLx
 {
     char *result = 0;
 
-    if (fmt != 0) {
+    if (SP_PARM != 0 && fmt != 0) {
 #if USE_SAFE_SPRINTF
        va_list ap2;
        int len;
@@ -258,9 +259,9 @@ NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_DCLx
 
        if (my_buffer != 0) {
 # if HAVE_VSNPRINTF
-           vsnprintf(my_buffer, my_length, fmt, ap);   /* GNU extension */
+           vsnprintf(my_buffer, my_length, fmt, ap);   /* SUSv2, 1997 */
 # else
-           vsprintf(my_buffer, fmt, ap);       /* ANSI */
+           vsprintf(my_buffer, fmt, ap);       /* ISO/ANSI C, 1989 */
 # endif
            result = my_buffer;
        }