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/changes.txt | 3 ++- externals/grill/flext/flext.cw | Bin 897507 -> 897507 bytes externals/grill/flext/source/flatom_pr.cpp | 23 +++++++++++------------ externals/grill/flext/source/flstdc.h | 2 +- externals/grill/flext/source/flsupport.cpp | 25 +++++++++++++++---------- externals/grill/flext/source/flsupport.h | 10 +++++----- 6 files changed, 34 insertions(+), 29 deletions(-) (limited to 'externals/grill/flext') diff --git a/externals/grill/flext/changes.txt b/externals/grill/flext/changes.txt index f5964072..aabe6949 100644 --- a/externals/grill/flext/changes.txt +++ b/externals/grill/flext/changes.txt @@ -23,6 +23,7 @@ Version history: - support for MinGW - added flext_obj::CanvasArgs - fixed small problem with buffer->Valid() on startup +- fixed buffer overrun problems with flext::post, flext::error... (but still to improve) 0.4.5: - added some more SIMD functions @@ -306,7 +307,7 @@ bugs: - flext_dsp: Max/MSP doesn't correctly report in/out channel counts - linker problems between MFC libraries and global new and delete overloadings -- flext::post and flext::error should print via a worker thread +- flext::post and flext::error should print via a worker thread (and should be unlimited in characters) tests: diff --git a/externals/grill/flext/flext.cw b/externals/grill/flext/flext.cw index 897c7633..2d6608c8 100644 Binary files a/externals/grill/flext/flext.cw and b/externals/grill/flext/flext.cw differ diff --git a/externals/grill/flext/source/flatom_pr.cpp b/externals/grill/flext/source/flatom_pr.cpp index 2e35f89c..9d5eeb29 100644 --- a/externals/grill/flext/source/flatom_pr.cpp +++ b/externals/grill/flext/source/flatom_pr.cpp @@ -18,34 +18,38 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include #include +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + // \TODO take bufsz into account! bool flext::PrintAtom(const t_atom &a,char *buf,int bufsz) { bool ok = true; if(IsFloat(a)) { - STD::sprintf(buf,"%g",GetFloat(a)); + STD::snprintf(buf,bufsz,"%g",GetFloat(a)); } else if(IsInt(a)) { - STD::sprintf(buf,"%i",GetInt(a)); + STD::snprintf(buf,bufsz,"%i",GetInt(a)); } else if(IsSymbol(a)) { if(!FLEXT_ASSERT(GetSymbol(a))) *buf = 0; else - STD::strcpy(buf,GetString(a)); + STD::strncpy(buf,GetString(a),bufsz); } else if(IsPointer(a)) { - STD::sprintf(buf,"%p",GetPointer(a)); + STD::snprintf(buf,bufsz,"%p",GetPointer(a)); } #if FLEXT_SYS == FLEXT_SYS_PD else if(a.a_type == A_DOLLAR) { - STD::sprintf(buf,"$%d",a.a_w.w_index); + STD::snprintf(buf,bufsz,"$%d",a.a_w.w_index); } else if(a.a_type == A_DOLLSYM) { - STD::sprintf(buf,"$%s",GetString(a)); + STD::snprintf(buf,bufsz,"$%s",GetString(a)); } #elif FLEXT_SYS == FLEXT_SYS_MAX else if(a.a_type == A_DOLLAR) { - STD::sprintf(buf,"$%d",a.a_w.w_long); + STD::snprintf(buf,bufsz,"$%d",a.a_w.w_long); } #else //#pragma message("Not implemented") @@ -74,11 +78,6 @@ bool flext::PrintList(int argc,const t_atom *argv,char *buf,int bufsz) return ok; } -bool flext::AtomList::Print(char *buffer,int buflen) const -{ - return flext::PrintList(Count(),Atoms(),buffer,buflen); -} - bool flext::ScanAtom(t_atom &a,const char *buf) { diff --git a/externals/grill/flext/source/flstdc.h b/externals/grill/flext/source/flstdc.h index 4927435c..f55b362b 100644 --- a/externals/grill/flext/source/flstdc.h +++ b/externals/grill/flext/source/flstdc.h @@ -111,7 +111,7 @@ typedef t_int t_flint; typedef t_symbol *t_symtype; typedef t_object *t_thing; -typedef qelem t_qelem; +typedef void *t_qelem; typedef method t_method; typedef method t_newmethod; 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); diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h index f8191fd3..fca7535e 100644 --- a/externals/grill/flext/source/flsupport.h +++ b/externals/grill/flext/source/flsupport.h @@ -35,10 +35,10 @@ class FLEXT_SHARE FLEXT_CLASSDEF(flext_root) { public: // --- console output ----------------------------------------------- - //! post message to console - static void post(const char *s,...); - //! post error message to console - static void error(const char *s,...); + //! post message to console, with line feed (limited to 1k chars!) + static void post(const char *fmt,...); + //! post error message to console (limited to 1k chars!) + static void error(const char *fmt,...); // --- memory ------------------------------------------------------- @@ -567,7 +567,7 @@ public: AtomList &Part(int offs,int len) { return (*this = GetPart(offs,len)); } //! Represent as a string - bool Print(char *buffer,int buflen) const; + bool Print(char *buffer,int buflen) const { return flext::PrintList(Count(),Atoms(),buffer,buflen); } protected: int cnt; -- cgit v1.2.1