[winpr] Make Stream_SafeSeek log a failure

This commit is contained in:
Armin Novak 2023-01-18 10:42:17 +01:00 committed by Martin Fleisz
parent d4d2b4403c
commit f62c658e17
2 changed files with 13 additions and 8 deletions

View File

@ -462,14 +462,9 @@ extern "C"
memset(_s->buffer, 0, _s->capacity);
}
static INLINE BOOL Stream_SafeSeek(wStream* s, size_t size)
{
if (Stream_GetRemainingLength(s) < size)
return FALSE;
Stream_Seek(s, size);
return TRUE;
}
#define Stream_SafeSeek(s, size) Stream_SafeSeekEx(s, size, __FILE__, __LINE__, __FUNCTION__)
WINPR_API BOOL Stream_SafeSeekEx(wStream* s, size_t size, const char* file, size_t line,
const char* fkt);
WINPR_API BOOL Stream_Read_UTF16_String(wStream* s, WCHAR* dst, size_t charLength);
WINPR_API BOOL Stream_Write_UTF16_String(wStream* s, const WCHAR* src, size_t charLength);

View File

@ -439,3 +439,13 @@ SSIZE_T Stream_Read_UTF16_String_As_UTF8_Buffer(wStream* s, size_t wcharLength,
Stream_Seek(s, wcharLength * sizeof(WCHAR));
return ConvertWCharNToUtf8(ptr, wcharLength, utfBuffer, utfBufferCharLength);
}
BOOL Stream_SafeSeekEx(wStream* s, size_t size, const char* file, size_t line, const char* fkt)
{
if (!Stream_CheckAndLogRequiredLengthEx(STREAM_TAG, WLOG_WARN, s, size, "%s(%s:%" PRIuz ")",
fkt, file, line))
return FALSE;
Stream_Seek(s, size);
return TRUE;
}