-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Describe the bug
A clear and concise description of what the bug is.
https://github.com/apache/incubator-doris/blob/e16873a6c1bbf0cf9e97f7a7bfd60b162eea4e31/be/src/udf/udf.h#L634-L648
StringVal::operator==() will check is_null, len & content(*ptr).
But when a StringVal obj sval len==0, the ptr can be NULL. It's possible to pass NULL ptr to memcmp(). Ref https://en.cppreference.com/w/c/string/byte/memcmp, The behavior is undefined if either lhs or rhs is a null pointer.
It's better to fix it.
StringVal StringFunctions::substring(
FunctionContext* context, const StringVal& str,
const IntVal& pos, const IntVal& len)
StringFunctions::substring() will return StringVal() when arg len == 0, StringVal() will set ptr to NULL, len to 0.
If we don't want to give a len == 0 StringVal an empty string('\0'), we should skip memcmp() when lhs or rhs len == 0.
To Reproduce
Steps to reproduce the behavior:
- compare
StringVal(len=0, ptr="")withStringVal().