Skip to content

Commit

Permalink
don't resize vector when the type flen is unspecified
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
  • Loading branch information
YangKeao committed Mar 7, 2024
1 parent bb7fc21 commit 4f28788
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/tidb_query_expr/src/impl_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,8 +1385,9 @@ fn cast_string_as_json(
let mut vec;
if typ.tp() == FieldTypeTp::String {
vec = (*val).to_owned();
// the `flen` of string is always greater than zero
vec.resize(typ.flen().try_into().unwrap(), 0);
if typ.flen() > 0 {
vec.resize(typ.flen().try_into().unwrap(), 0);
}
buf = &vec;
}

Expand Down Expand Up @@ -7022,6 +7023,17 @@ mod tests {
Json::from_opaque(FieldTypeTp::String, &[97]).unwrap(),
true,
),
(
FieldTypeBuilder::new()
.tp(FieldTypeTp::VarChar)
.flen(FlenType::Unspecified)
.charset(CHARSET_BIN)
.collation(Collation::Binary)
.build(),
"a".to_string(),
Json::from_opaque(FieldTypeTp::String, &[97]).unwrap(),
true,
),
];
for (arg_type, input, expect, parse_to_json) in cs {
let arg_value = ScalarValue::Bytes(Some(input.clone().into_bytes()));
Expand Down

0 comments on commit 4f28788

Please sign in to comment.