From 5b821a81fc7c9ed7decfe5575a867ab82464b0cc Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Fri, 26 Mar 2004 03:22:11 +0000 Subject: "" svn path=/trunk/; revision=1480 --- externals/grill/flext/source/flsupport.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'externals/grill/flext/source/flsupport.cpp') diff --git a/externals/grill/flext/source/flsupport.cpp b/externals/grill/flext/source/flsupport.cpp index cc300b95..c453aae2 100644 --- a/externals/grill/flext/source/flsupport.cpp +++ b/externals/grill/flext/source/flsupport.cpp @@ -18,6 +18,11 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include #include +#ifdef _MSC_VER +#define vsnprintf _vsnprintf +#define snprintf _snprintf +#endif + const t_symbol *flext::sym_float = NULL; const t_symbol *flext::sym_symbol = NULL; const t_symbol *flext::sym_bang = NULL; @@ -263,10 +268,9 @@ void flext::GetAString(const t_atom &a,char *buf,int szbuf) #if FLEXT_SYS == FLEXT_SYS_PD atom_string(const_cast(&a),buf,szbuf); #else - // no checking for size here - if(IsSymbol(a)) STD::sprintf(buf,GetString(a)); - else if(IsFloat(a)) STD::sprintf(buf,"%f",GetFloat(a)); - else if(IsInt(a)) STD::sprintf(buf,"%i",GetInt(a)); + if(IsSymbol(a)) STD::strncpy(buf,GetString(a),szbuf); + else if(IsFloat(a)) STD::snprintf(buf,szbuf,"%f",GetFloat(a)); + else if(IsInt(a)) STD::snprintf(buf,szbuf,"%i",GetInt(a)); else *buf = 0; #endif } @@ -280,14 +284,14 @@ unsigned long flext::AtomHash(const t_atom &a) #endif } - void flext_root::post(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - char buf[1024]; // \TODO this is quite unsafe..... - vsprintf(buf, fmt, ap); + char buf[1024]; + vsnprintf(buf,sizeof buf,fmt, ap); + buf[sizeof buf-1] = 0; // in case of full buffer ::post(buf); va_end(ap); @@ -298,9 +302,10 @@ void flext_root::error(const char *fmt,...) va_list ap; va_start(ap, fmt); - char buf[1024]; // \TODO this is quite unsafe..... - STD::sprintf(buf,"error: "); - vsprintf(buf+7, fmt, ap); + char buf[1024]; + strcpy(buf,"error: "); + vsnprintf(buf+7,sizeof buf-7,fmt, ap); + buf[sizeof buf-1] = 0; // in case of full buffer ::post(buf); va_end(ap); -- cgit v1.2.1