[Bug](function) core dump on substr #13007

This commit is contained in:
Pxl
2022-09-28 08:54:49 +08:00
committed by GitHub
parent 2dafbda9de
commit ee3dd423b9
3 changed files with 32 additions and 0 deletions

View File

@ -187,6 +187,10 @@ private:
}
int fixed_pos = start[i];
if (fixed_pos < -(int)index.size()) {
StringOP::push_empty_string(i, res_chars, res_offsets);
continue;
}
if (fixed_pos < 0) {
fixed_pos = index.size() + fixed_pos + 1;
}

View File

@ -236,3 +236,24 @@ c1
-- !sql --
bc
-- !sql --
-- !sql --
-- !sql --
a
-- !sql --
-- !sql --
a
-- !sql --
-- !sql --

View File

@ -125,4 +125,11 @@ suite("test_string_function") {
qt_sql "select substring('abc1', 5);"
qt_sql "select substring('abc1def', 2, 2);"
qt_sql "select substr('a',3,1);"
qt_sql "select substr('a',2,1);"
qt_sql "select substr('a',1,1);"
qt_sql "select substr('a',0,1);"
qt_sql "select substr('a',-1,1);"
qt_sql "select substr('a',-2,1);"
qt_sql "select substr('a',-3,1);"
}