log caller/lineno when string in stream too long

I'm seeing it and so want it logged in the future
This commit is contained in:
Eric House 2022-05-13 18:02:09 -07:00
parent a281bb25a7
commit 2937aed7e1
2 changed files with 23 additions and 3 deletions

View file

@ -249,11 +249,18 @@ p_stringFromStream( MPFORMAL XWStreamCtxt* stream
} /* makeStringFromStream */
XP_U16
stringFromStreamHere( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 buflen )
stringFromStreamHereImpl( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 buflen
#ifdef DEBUG
, const char* func, int line
#endif
)
{
XP_U16 len = stream_getU8( stream );
if ( len > 0 ) {
XP_ASSERT( len < buflen );
if ( buflen <= len ) {
XP_LOGFF( "BAD: buflen %d < len %d (from %s(), line %d)", buflen, len, func, line );
XP_ASSERT(0);
}
if ( len >= buflen ) {
/* better to leave stream in bad state than overwrite stack */
len = buflen - 1;
@ -271,6 +278,7 @@ stringToStream( XWStreamCtxt* stream, const XP_UCHAR* str )
if ( len > 0xFF ) {
XP_LOGFF( "truncating string '%s', dropping len from %d to %d",
str, len, 0xFF );
XP_ASSERT(0);
len = 0xFF;
}
stream_putU8( stream, (XP_U8)len );

View file

@ -61,7 +61,19 @@ XP_UCHAR* p_stringFromStream( MPFORMAL XWStreamCtxt* stream
# define stringFromStream( p, in ) p_stringFromStream( in )
#endif
XP_U16 stringFromStreamHere( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 len );
XP_U16 stringFromStreamHereImpl( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 len
#ifdef DEBUG
,const char* func, int line
#endif
);
#ifdef DEBUG
# define stringFromStreamHere( stream, buf, len ) \
stringFromStreamHereImpl( (stream), (buf), (len), __func__, __LINE__ )
#else
# define stringFromStreamHere( stream, buf, len ) \
stringFromStreamHereImpl( (stream), (buf), (len))
#endif
void stringToStream( XWStreamCtxt* stream, const XP_UCHAR* str );
XP_Bool stream_gotU8( XWStreamCtxt* stream, XP_U8* ptr );