/****************************************************************************
- * Copyright (c) 1998-2010,2012 Free Software Foundation, Inc. *
+ * Copyright 2018,2020 Thomas E. Dickey *
+ * Copyright 1998-2012,2013 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.33 2020/02/02 23:34:34 tom Exp $")
#if USE_SAFE_SPRINTF
Flags, Width, Prec, Type, Format
} PRINTF;
-#define VA_INTGR(type) ival = va_arg(ap, type)
+#define VA_INTGR(type) ival = (int) va_arg(ap, type)
#define VA_FLOAT(type) fval = va_arg(ap, type)
#define VA_POINT(type) pval = (void *)va_arg(ap, type)
"%d", ival);
fmt_len += strlen(fmt_arg);
if ((format = _nc_doalloc(format, fmt_len)) == 0) {
+ free(buffer);
return -1;
}
--f;
case 's':
VA_POINT(char *);
if (prec < 0)
- prec = strlen(pval);
+ prec = (int) strlen(pval);
if (prec > (int) length) {
- length = length + prec;
+ length = length + (size_t) prec;
buffer = typeRealloc(char, length, buffer);
if (buffer == 0) {
free(format);
{
char *result = 0;
- if (fmt != 0) {
+ if (SP_PARM != 0 && fmt != 0) {
#if USE_SAFE_SPRINTF
va_list ap2;
int len;
end_va_copy(ap2);
if ((int) my_length < len + 1) {
- my_length = 2 * (len + 1);
+ my_length = (size_t) (2 * (len + 1));
my_buffer = typeRealloc(char, my_length, my_buffer);
}
if (my_buffer != 0) {
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;
}