From 2132f900f65f521c61e60a3541716104d83ee384 Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:00:21 +0000 Subject: Utilisateur : Fcolin Date : 17/11/05 Heure : 15:08 Archivé dans $/Bus/Ivy Commentaire: nice Bug in nextArg not reentrant routine due to static variable (vss 27) --- Ivy/IvyApplication.cxx | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'Ivy') diff --git a/Ivy/IvyApplication.cxx b/Ivy/IvyApplication.cxx index 5a50b96..32b89a2 100644 --- a/Ivy/IvyApplication.cxx +++ b/Ivy/IvyApplication.cxx @@ -9,36 +9,32 @@ //#define IVY_DEBUG -#define ARG_START "\002" -#define ARG_END "\003" +#define ARG_START 2 +#define ARG_END 3 -static char * firstArg( char *s, const char *separator ) +static char * firstArg( char *s, const char separator ) { char *ptr = s; - while ( *ptr && *ptr != *separator ) + while ( *ptr && *ptr != separator ) ptr++; - if ( *ptr == *separator ) + if ( *ptr == separator ) return ptr++ ; else return NULL; } /* function like strok but do not eat consecutive separator */ -static char * nextArg( char *s, const char *separator ) +static char * nextArg( char **s, const char separator ) { - static char *start = NULL; - static char *end = NULL; - if ( s ) - { - end = s; - } - start = end; + char *start = *s; + char *end = *s; - while ( *end && *end != *separator ) + while ( *end && *end != separator ) end++; - if ( *end == *separator ) *end++ = '\0'; + if ( *end == separator ) *end++ = '\0'; if ( end == start ) return NULL; + *s = end; return start; } ///////////////////////////////////////////////////////////////////////////// @@ -102,6 +98,7 @@ void IvyApplication::OnReceive(char * line) int kind_of_msg = Bye; char *arg; int argc = 0; + char *arg_ptr; #ifdef USE_PCRE pcre *exp; @@ -243,11 +240,12 @@ void IvyApplication::OnReceive(char * line) TRACE("Message id=%d msg='%s'\n", id, arg); #endif //IVY_DEBUG - arg = nextArg( arg, ARG_END); + arg_ptr = arg; + arg = nextArg( &arg_ptr, ARG_END); while ( arg ) { argv[argc++] = arg; - arg = nextArg( NULL, ARG_END ); + arg = nextArg( &arg_ptr, ARG_END ); } bus->CallMessageCallback( this, id, argc, argv ); break; @@ -283,8 +281,8 @@ void IvyApplication::SendMsg(MsgType msg, int id, const char * arg) { char buffer[1024]; if ( arg ) - _snprintf_s( buffer, sizeof( buffer ),sizeof( buffer )-1, "%d %d" ARG_START "%s\n", msg, id, arg ); - else sprintf_s( buffer,sizeof( buffer ), "%d %d" ARG_START "\n", msg, id ); + _snprintf_s( buffer, sizeof( buffer ),sizeof( buffer )-1, "%d %d%c%s\n", msg, id, ARG_START, arg ); + else sprintf_s( buffer,sizeof( buffer ), "%d %d%c\n", msg, id, ARG_START); #ifdef IVY_DEBUG TRACE("SendMsg %s\n",buffer); -- cgit v1.1