Index: src/main/printutils.c =================================================================== --- src/main/printutils.c (revision 60410) +++ src/main/printutils.c (working copy) @@ -81,6 +81,9 @@ extern int R_OutputCon; /* from connections.c */ +#ifndef min +#define min(a, b) (((a)<(b))?(a):(b)) +#endif #define BUFSIZE 8192 /* used by Rprintf etc */ @@ -132,7 +135,7 @@ { static char buff[NB]; if(x == NA_INTEGER) snprintf(buff, NB, "%*s", w, CHAR(R_print.na_string)); - else snprintf(buff, NB, "%*d", w, x); + else snprintf(buff, NB, "%*d", min(w, (NB-1)), x); buff[NB-1] = '\0'; return buff; } @@ -179,16 +182,16 @@ } else if (e) { if(d) { - sprintf(fmt,"%%#%d.%de", w, d); + sprintf(fmt,"%%#%d.%de", min(w, (NB-1)), d); snprintf(buff, NB, fmt, x); } else { - sprintf(fmt,"%%%d.%de", w, d); + sprintf(fmt,"%%%d.%de", min(w, (NB-1)), d); snprintf(buff, NB, fmt, x); } } else { /* e = 0 */ - sprintf(fmt,"%%%d.%df", w, d); + sprintf(fmt,"%%%d.%df", min(w, (NB-1)), d); snprintf(buff, NB, fmt, x); } buff[NB-1] = '\0'; @@ -215,16 +218,16 @@ } else if (e) { if(d) { - sprintf(fmt,"%%#%d.%de", w, d); + sprintf(fmt,"%%#%d.%de", min(w, (NB-1)), d); snprintf(buff, NB, fmt, x); } else { - sprintf(fmt,"%%%d.%de", w, d); + sprintf(fmt,"%%%d.%de", min(w, (NB-1)), d); snprintf(buff, NB, fmt, x); } } else { /* e = 0 */ - sprintf(fmt,"%%#%d.%df", w, d); + sprintf(fmt,"%%#%d.%df", min(w, (NB-1)), d); snprintf(buff, NB, fmt, x); } buff[NB-1] = '\0';