/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999 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 *
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: safe_sprintf.c,v 1.5 1998/02/11 12:13:57 tom Exp $")
+MODULE_ID("$Id: safe_sprintf.c,v 1.11 1999/09/11 18:03:27 tom Exp $")
#if USE_SAFE_SPRINTF
if (fmt == 0 || *fmt == '\0')
return -1;
- if ((format = malloc(strlen(fmt)+1)) == 0)
+ if ((format = typeMalloc(char, strlen(fmt)+1)) == 0)
return -1;
- if ((buffer = malloc(length)) == 0) {
+ if ((buffer = typeMalloc(char, length)) == 0) {
free(format);
return -1;
}
while (*fmt != '\0') {
if (*fmt == '%') {
+ static char dummy[] = "";
PRINTF state = Flags;
- char *pval = "";
+ char *pval = dummy; /* avoid const-cast */
double fval = 0.0;
int done = FALSE;
int ival = 0;
case 'Z': /* FALLTHRU */
case 'h': /* FALLTHRU */
case 'l': /* FALLTHRU */
- case 'L': /* FALLTHRU */
done = FALSE;
type = *fmt;
break;
case 'E': /* FALLTHRU */
case 'g': /* FALLTHRU */
case 'G': /* FALLTHRU */
- if (type == 'L')
- VA_FLOAT(long double);
- else
- VA_FLOAT(double);
+ VA_FLOAT(double);
used = 'f';
break;
case 'c':
prec = strlen(pval);
if (prec > (int)length) {
length = length + prec;
- buffer = realloc(buffer, length);
+ buffer = typeRealloc(char, length, buffer);
if (buffer == 0) {
free(format);
return -1;
int len = _nc_printf_length(fmt, ap);
if (len > 0) {
- buf = malloc(len+1);
+ if ((buf = typeMalloc(char, len+1)) == 0)
+ return(0);
vsprintf(buf, fmt, ap);
}
#else
if (screen_lines > rows) rows = screen_lines;
if (screen_columns > cols) cols = screen_columns;
len = (rows * (cols + 1)) + 1;
- if (buf == 0)
- buf = malloc(len);
- else
- buf = realloc(buf, len);
+ buf = typeRealloc(char, len, buf);
+ if (buf == 0) {
+ return(0);
+ }
}
if (buf != 0) {
# else
vsprintf(buf, fmt, ap); /* ANSI */
# endif
-#endif
}
+#endif
return buf;
}