X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Fsafe_sprintf.c;fp=ncurses%2Fbase%2Fsafe_sprintf.c;h=9cea066ca24c81f558a8aa52041bb6b65efc7e65;hp=e73307bac2826ee7b7517e1d8cf06299f7e7b7ad;hb=8b06e371ed1bce3dd6f37138e6becb5e1a562fe0;hpb=a3173aa5edbdbc6d617800f81a88a304ac5e053c diff --git a/ncurses/base/safe_sprintf.c b/ncurses/base/safe_sprintf.c index e73307ba..9cea066c 100644 --- a/ncurses/base/safe_sprintf.c +++ b/ncurses/base/safe_sprintf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. * + * Copyright (c) 1998-2010,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 * @@ -33,7 +33,7 @@ #include #include -MODULE_ID("$Id: safe_sprintf.c,v 1.24 2010/06/05 22:22:27 tom Exp $") +MODULE_ID("$Id: safe_sprintf.c,v 1.26 2012/02/22 22:40:24 tom Exp $") #if USE_SAFE_SPRINTF @@ -109,12 +109,15 @@ _nc_printf_length(const char *fmt, va_list ap) } else if (state == Prec) { prec = ival; } - sprintf(fmt_arg, "%d", ival); + _nc_SPRINTF(fmt_arg, + _nc_SLIMIT(sizeof(fmt_arg)) + "%d", ival); fmt_len += strlen(fmt_arg); if ((format = _nc_doalloc(format, fmt_len)) == 0) { return -1; } - strcpy(&format[--f], fmt_arg); + --f; + _nc_STRCPY(&format[f], fmt_arg, fmt_len - f); f = strlen(format); } else if (isalpha(UChar(*fmt))) { done = TRUE; @@ -185,13 +188,13 @@ _nc_printf_length(const char *fmt, va_list ap) format[f] = '\0'; switch (used) { case 'i': - sprintf(buffer, format, ival); + _nc_SPRINTF(buffer, _nc_SLIMIT(length) format, ival); break; case 'f': - sprintf(buffer, format, fval); + _nc_SPRINTF(buffer, _nc_SLIMIT(length) format, fval); break; default: - sprintf(buffer, format, pval); + _nc_SPRINTF(buffer, _nc_SLIMIT(length) format, pval); break; } len += (int) strlen(buffer);