mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
fix to read any length string from stream
This commit is contained in:
parent
dc0c63dc24
commit
3c56490c01
1 changed files with 8 additions and 9 deletions
|
@ -233,20 +233,19 @@ p_stringFromStream( MPFORMAL XWStreamCtxt* stream
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
/* PENDING: Hard-coded max buffer size is wrong!!! stringFromStreamHere()
|
XP_U16 version = stream_getVersion( stream );
|
||||||
needs to "peek" and return the size required. Or better, call XP_MALLOC
|
XP_U32 len = version < STREAM_VERS_NORELAY ? stream_getU8( stream )
|
||||||
itself (with mpool passed in?) */
|
: stream_getU32VL( stream );
|
||||||
XP_UCHAR buf[1024];
|
|
||||||
XP_UCHAR* str = (XP_UCHAR*)NULL;
|
|
||||||
XP_U16 len = stringFromStreamHere( stream, buf, sizeof(buf) );
|
|
||||||
|
|
||||||
if ( len > 0 ) {
|
XP_UCHAR* str = NULL;
|
||||||
|
if ( 0 < len ) {
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
str = mpool_alloc( mpool, len + 1, file, func, lineNo );
|
str = mpool_alloc( mpool, len + 1, file, func, lineNo );
|
||||||
#else
|
#else
|
||||||
str = (XP_UCHAR*)XP_MALLOC( mpool, len + 1 ); /* leaked */
|
str = (XP_UCHAR*)XP_MALLOC( mpool, len + 1 );
|
||||||
#endif
|
#endif
|
||||||
XP_MEMCPY( str, buf, len + 1 );
|
stream_getBytes( stream, str, len );
|
||||||
|
str[len] = '\0';
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
} /* makeStringFromStream */
|
} /* makeStringFromStream */
|
||||||
|
|
Loading…
Reference in a new issue