1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

fix(funcexp): MCOL-4671 Fix behaviour of LEFT/RIGHT functions when negative trim length value is passedB

This commit is contained in:
Alexander Presnyakov
2024-07-03 19:11:19 +04:00
committed by Leonid Fedorov
parent 37852e9234
commit 57e2375dbc
4 changed files with 97 additions and 5 deletions

View File

@ -56,15 +56,17 @@ std::string Func_right::getStrVal(rowgroup::Row& row, FunctionParm& fp, bool& is
const char* pos = src.str();
const char* end = pos + binLen;
size_t trimLength = fp[1]->data()->getUintVal(row, isNull);
// Negative trim length values are legal, but they don't make any real sense
int64_t trimLength = fp[1]->data()->getUintVal(row, isNull);
if (isNull || trimLength <= 0)
return "";
size_t trimLengthPositive = static_cast<size_t>(trimLength); // now we are sure it is positive
size_t start = cs->numchars(pos, end); // Here, start is number of characters in src
if (start <= trimLength)
if (start <= trimLengthPositive)
return src.safeString("");
start = cs->charpos(pos, end,
start - trimLength); // Here, start becomes number of bytes into src to start copying
start - trimLengthPositive); // Here, start becomes number of bytes into src to start copying
std::string ret(pos + start, binLen - start);
return ret;