From bfd31350c2e1123408d02b9395f87ba8a5c7258f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 27 Oct 2008 10:26:54 +0000 Subject: [PATCH] 2008-10-27 11:26 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * source/common/hbstr.c * Some tweaks to hb_snprintf(). It still doesn't work for some reason. * include/hbapi.h + Added hb_snprintf() to header. * source/debug/dbgentry.c * Changed strcpy() to hb_strncpy(). Chances are high this is wrong. Please review and test. --- harbour/ChangeLog | 12 ++++++++++++ harbour/include/hbapi.h | 13 +++++++------ harbour/source/common/hbstr.c | 18 ++++++++---------- harbour/source/debug/dbgentry.c | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index bbdeef1abc..53fd080dbf 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,18 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-10-27 11:26 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + * source/common/hbstr.c + * Some tweaks to hb_snprintf(). It still doesn't work + for some reason. + + * include/hbapi.h + + Added hb_snprintf() to header. + + * source/debug/dbgentry.c + * Changed strcpy() to hb_strncpy(). Chances are high + this is wrong. Please review and test. + 2008-10-27 10:37 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * source/pp/ppcore.c + Added '#pragma TEXTHIDDEN=' to control the diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index d1f0917137..c1edc93340 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -821,12 +821,13 @@ extern HB_EXPORT char * hb_strndup( const char * pszText, ULONG ulLen ); /* r extern HB_EXPORT char * hb_strduptrim( const char * pszText ); /* returns a pointer to a newly allocated copy of the trimmed source string */ extern HB_EXPORT ULONG hb_strlentrim( const char * pszText ); /* like strlen() but result is the length of trimmed text */ extern HB_EXPORT ULONG hb_strnlen( const char * pszText, ULONG ulLen ); /* like strlen() but result is limited to ulLen */ -extern HB_EXPORT char * hb_xstrcat( char *dest, const char *src, ... ); /* Concatenates multiple strings into a single result */ -extern HB_EXPORT char * hb_xstrcpy( char *szDest, const char *szSrc, ...); /* Concatenates multiple strings into a single result */ -extern HB_EXPORT BOOL hb_compStrToNum( const char* szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ); /* converts string to number, sets iDec, iWidth and returns TRUE if results is double, used by compiler */ -extern HB_EXPORT BOOL hb_valStrnToNum( const char* szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ); /* converts string to number, sets iDec, iWidth and returns TRUE if results is double, used by VAL() */ -extern HB_EXPORT BOOL hb_strToNum( const char* szNum, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ -extern HB_EXPORT BOOL hb_strnToNum( const char* szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ +extern HB_EXPORT char * hb_xstrcat( char * dest, const char * src, ... ); /* Concatenates multiple strings into a single result */ +extern HB_EXPORT char * hb_xstrcpy( char * szDest, const char * szSrc, ... ); /* Concatenates multiple strings into a single result */ +extern HB_EXPORT BOOL hb_compStrToNum( const char * szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ); /* converts string to number, sets iDec, iWidth and returns TRUE if results is double, used by compiler */ +extern HB_EXPORT BOOL hb_valStrnToNum( const char * szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal, int * piDec, int * piWidth ); /* converts string to number, sets iDec, iWidth and returns TRUE if results is double, used by VAL() */ +extern HB_EXPORT BOOL hb_strToNum( const char * szNum, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ +extern HB_EXPORT BOOL hb_strnToNum( const char * szNum, ULONG ulLen, HB_LONG * plVal, double * pdVal ); /* converts string to number, returns TRUE if results is double */ +extern HB_EXPORT void hb_snprintf( char * buffer, ULONG nSize, const char * format, ... ); /* snprintf() wrapper */ extern HB_EXPORT BOOL hb_strMatchFile( const char * pszString, const char * szPattern ); /* compare two strings using platform dependent rules for file matching */ extern HB_EXPORT BOOL hb_strMatchRegExp( const char * szString, const char * szPattern ); /* compare two strings using a regular expression pattern */ diff --git a/harbour/source/common/hbstr.c b/harbour/source/common/hbstr.c index abbccdb7ed..53fe4e37d6 100644 --- a/harbour/source/common/hbstr.c +++ b/harbour/source/common/hbstr.c @@ -1112,29 +1112,27 @@ char * hb_compDecodeString( int iMethod, const char * szText, ULONG * pulLen ) #undef _HB_SNPRINTF_ADD_EOS #undef snprintf /* NOTE: The full size of the buffer is expected as nSize. [vszakats] */ -HB_EXPORT void hb_snprintf( char * buffer, ULONG nSize, ... ) +HB_EXPORT void hb_snprintf( char * buffer, ULONG nSize, const char * format, ... ) { - va_list va; + va_list arglist; - va_start( va, nSize ); + va_start( arglist, format ); #if defined( __DJGPP__ ) && ( __DJGPP__ < 2 || ( __DJGPP__ == 2 && __DJGPP_MINOR__ <= 3 ) ) /* Use sprintf() for DJGPP <= 2.03. This is a temporary hack, should implement a C99 snprintf() ourselves. */ - sprintf( buffer, va ); + sprintf( buffer, format, arglist ); #elif defined( _MSC_VER ) && _MSC_VER >= 1400 - _snprintf_s( buffer, nSize, _TRUNCATE, va ); + _snprintf_s( buffer, nSize, _TRUNCATE, format, arglist ); #elif defined( _MSC_VER ) || defined( __DMC__ ) && !defined( __XCC__ ) - _snprintf( buffer, nSize, va ); + _snprintf( buffer, nSize, format, arglist ); #define _HB_SNPRINTF_ADD_EOS #elif defined( __WATCOMC__ ) && __WATCOMC__ < 1200 - _bprintf( buffer, nSize, va ); + _bprintf( buffer, nSize, format, arglist ); #else - snprintf( buffer, nSize, va ); + snprintf( buffer, nSize, format, arglist ); #endif - va_end( va ); - #ifdef _HB_SNPRINTF_ADD_EOS if( buffer && nSize ) buffer[ nSize - 1 ] = '\0'; diff --git a/harbour/source/debug/dbgentry.c b/harbour/source/debug/dbgentry.c index dcbc71d3a0..7f29e42e87 100644 --- a/harbour/source/debug/dbgentry.c +++ b/harbour/source/debug/dbgentry.c @@ -1056,7 +1056,7 @@ hb_dbgEvalSubstituteVar( HB_WATCHPOINT *watch, char *szWord, int nStart, int nLe t[ nStart + 6 ] = '0' + ( char ) ( ( j + 1 ) / 10 ); t[ nStart + 7 ] = '0' + ( char ) ( ( j + 1 ) % 10 ); t[ nStart + 8 ] = ']'; - strcpy( t + nStart + 9, watch->szExpr + nStart + nLen ); + hb_strncpy( t + nStart + 9, watch->szExpr + nStart + nLen, strlen( watch->szExpr ) - nLen + 1 - nStart ); FREE( watch->szExpr ); watch->szExpr = t; return nStart + 9;