Index: trunk/src/lib/network/synchronizeable.h
===================================================================
--- trunk/src/lib/network/synchronizeable.h	(revision 6959)
+++ trunk/src/lib/network/synchronizeable.h	(revision 7230)
@@ -199,12 +199,7 @@
 }
 #define SYNCHELP_WRITE_STRING(s,n) { SYNCHELP_WRITE_DEBUG(n); \
-                                if (s!=NULL) {\
                                 __synchelp_write_n = \
-                                Converter::stringToByteArray( s, data+__synchelp_write_i, strlen(s), maxLength-__synchelp_write_i ); \
-                                assert( __synchelp_write_n == strlen(s)+INTSIZE ); \
-                                } else {\
-                                __synchelp_write_n = \
-                                Converter::stringToByteArray( "", data+__synchelp_write_i, strlen(""), maxLength-__synchelp_write_i ); \
-                                assert( __synchelp_write_n == strlen("")+INTSIZE ); } \
+                                Converter::stringToByteArray( s, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
+                                assert( __synchelp_write_n == ((std::string)s).length()+INTSIZE ); \
                                 if ( __synchelp_write_n <= 0) \
 { \
@@ -216,6 +211,16 @@
 #define SYNCHELP_WRITE_N        __synchelp_write_i
 #define SYNCHELP_WRITE_FKT(f,n)   { SYNCHELP_WRITE_DEBUG(n); \
-                                  __synchelp_write_i += \
+                                  PRINTF(0)("calling %s with %d left\n", #f, maxLength - __synchelp_write_i);  \
+                                  byte * spos = data+__synchelp_write_i;  \
+                                  if (maxLength - __synchelp_write_i < INTSIZE) \
+{ \
+                                    PRINTF(1)("Buffer is too small to store more data\n"); \
+                                    return 0; \
+} \
+                                  __synchelp_write_i += INTSIZE; \
+                                  __synchelp_write_n = \
                                   f( data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
+                                  __synchelp_write_i += __synchelp_write_n;  \
+                                  Converter::intToByteArray( __synchelp_write_n, spos, INTSIZE ); \
                                 }
 
@@ -244,7 +249,7 @@
                                     __synchelp_read_i += __synchelp_read_n; \
 }
-#define SYNCHELP_READ_STRING(s,l,n)    {SYNCHELP_READ_DEBUG(n); \
-                                    __synchelp_read_n = Converter::byteArrayToString( data+__synchelp_read_i, s, l );  \
-                                    assert( __synchelp_read_n == strlen(s)+INTSIZE ) ;\
+#define SYNCHELP_READ_STRING(s,n)    {SYNCHELP_READ_DEBUG(n); \
+                                    __synchelp_read_n = Converter::byteArrayToString( data+__synchelp_read_i, s, length-__synchelp_read_i );  \
+                                    assert( __synchelp_read_n == s.length()+INTSIZE ) ;\
                                     if ( __synchelp_read_n <0 )  \
 { \
@@ -254,4 +259,5 @@
                                     __synchelp_read_i += __synchelp_read_n; \
 }
+#if 0 //not needed any more
 #define SYNCHELP_READ_STRINGM(s,n)    { SYNCHELP_READ_DEBUG(n); \
                                     __synchelp_read_n = Converter::byteArrayToStringM( data+__synchelp_read_i, s );  \
@@ -264,4 +270,5 @@
                                     __synchelp_read_i += __synchelp_read_n; \
 }
+#endif
 #define SYNCHELP_READ_BYTE(b,n)      { SYNCHELP_READ_DEBUG(n); \
                                     if ( length-__synchelp_read_i < 1 ) \
@@ -274,6 +281,15 @@
 }
 #define SYNCHELP_READ_FKT(f,n)   { SYNCHELP_READ_DEBUG(n); \
+                                  int s; \
+                                  if ( length-__synchelp_read_i < INTSIZE ) \
+{ \
+                                      PRINTF(1)("There is not enough data to read an int\n");  \
+                                      return 0; \
+} \
+                                    __synchelp_read_n = Converter::byteArrayToInt( data+__synchelp_read_i, &s );  \
+                                    assert( __synchelp_read_n == INTSIZE ); \
+                                    __synchelp_read_i += __synchelp_read_n; \
                                   __synchelp_read_i += \
-                                  f( data+__synchelp_read_i, length-__synchelp_read_i, sender); \
+                                  f( data+__synchelp_read_i, s, sender); \
                                   }
 #define SYNCHELP_READ_REMAINING() ( length-__synchelp_read_i )
