From: <bo...@us...> - 2003-12-12 18:20:24
|
Update of /cvsroot/sharedaemon/core/src In directory sc8-pr-cvs1:/tmp/cvs-serv11584 Modified Files: ParseClass.cpp osdep.h Log Message: Fixed some errors of initial implementaion of Write - but there are still serious errors left Index: ParseClass.cpp =================================================================== RCS file: /cvsroot/sharedaemon/core/src/ParseClass.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- ParseClass.cpp 12 Dec 2003 16:48:54 -0000 1.14 +++ ParseClass.cpp 12 Dec 2003 18:20:21 -0000 1.15 @@ -649,6 +649,32 @@ ); } + /* + * Checking functionality: Write this instance back to a + * buffer, to see, if read/write is compatible. + */ + + u8 *cmp_buffer; + size_t cmp_buffsize; + + if (!Write(&cmp_buffer,&cmp_buffsize)) { + fprintf(stderr, + "%s:%s:%i: Warning: Write failed!\n" + ,__FILE__,__FUNCTION__,__LINE__ + ); + } else { + if (buffsize!=cmp_buffsize + || memcmp(buffer,cmp_buffer,buffsize)) { + fprintf(stderr, + "%s:%s:%i: Fatal: Write didn't return the " + "same data as just being Read in.\n" + ,__FILE__,__FUNCTION__,__LINE__ + ); + Write("wrondata.met"); + exit(1); + } + } + return true; } @@ -802,8 +828,8 @@ case IPPORT: last->data=new u8[6]; last->free=true; - *(u32*)(last->data )=htob32(*(u32*)dataptr ); - *(u16*)(last->data+4)=htol16(*(u16*)dataptr+4); + *(u32*)(last->data )=htob32(*(u32*)(dataptr )); + *(u16*)(last->data+4)=htol16(*(u16*)(dataptr+4)); break; default: @@ -843,12 +869,11 @@ n; ++tag,--n ) { - last->size=1+2+tag->id_len; - prev=last; last->next=new struct write_struct; last=last->next; + last->size=1+2+tag->id_len; ptr=last->data=new u8[last->size+4]; last->free=true; @@ -878,6 +903,7 @@ *(u16*)ptr=htol16(tag->value.string.length); + done+=last->size; prev=last; last->next=new struct write_struct; last=last->next; @@ -966,7 +992,8 @@ *buffer=new u8[*buffsize]; i=0; while (first) { - memcpy(buffer+i,first->data,first->size); + assert(i+first->size<=*buffsize); + memcpy(*buffer+i,first->data,first->size); i+=first->size; if (first->free) { Index: osdep.h =================================================================== RCS file: /cvsroot/sharedaemon/core/src/osdep.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- osdep.h 12 Dec 2003 16:48:54 -0000 1.13 +++ osdep.h 12 Dec 2003 18:20:21 -0000 1.14 @@ -58,10 +58,10 @@ #define btoh32(x) ntohl(x) #define htol16(x) bswap16(htons(x)) -#define htol32(x) bswap32(htons(x)) +#define htol32(x) bswap32(htonl(x)) #define ntol16(x) bswap16(x) #define ntol32(x) bswap32(x) -#define htob32(x) htons(x) +#define htob32(x) htonl(x) #ifdef MACOSX #include <sys/types.h> |