vagetablechicken opened a new issue #3843:
URL: https://github.com/apache/incubator-doris/issues/3843


   **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:
   1. compare `StringVal(len=0, ptr="")` with `StringVal()`.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to