summaryrefslogtreecommitdiff
path: root/Bus/Ivy
diff options
context:
space:
mode:
authorfcolin2007-02-01 13:00:21 +0000
committerfcolin2007-02-01 13:00:21 +0000
commit9f763ede1f2a090d40c828234c537b83e6980c63 (patch)
tree127108e4a5a0c4d7b157ece43384f2aacf73a670 /Bus/Ivy
parent6677578c8c3cf9983139da455c372abba4aa75ed (diff)
downloadivy-cplusplus-9f763ede1f2a090d40c828234c537b83e6980c63.zip
ivy-cplusplus-9f763ede1f2a090d40c828234c537b83e6980c63.tar.gz
ivy-cplusplus-9f763ede1f2a090d40c828234c537b83e6980c63.tar.bz2
ivy-cplusplus-9f763ede1f2a090d40c828234c537b83e6980c63.tar.xz
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)
Diffstat (limited to 'Bus/Ivy')
-rw-r--r--Bus/Ivy/IvyApplication.cxx36
1 files changed, 17 insertions, 19 deletions
diff --git a/Bus/Ivy/IvyApplication.cxx b/Bus/Ivy/IvyApplication.cxx
index 5a50b96..32b89a2 100644
--- a/Bus/Ivy/IvyApplication.cxx
+++ b/Bus/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);