@@ -10702,6 +10702,7 @@ dsc* StrCaseNode::execute(thread_db* tdbb, jrd_req* request) const
10702
10702
return NULL ;
10703
10703
10704
10704
TextType* textType = INTL_texttype_lookup (tdbb, value->getTextType ());
10705
+ CharSet* charSet = textType->getCharSet ();
10705
10706
auto intlFunction = (blrOp == blr_lowcase ? &TextType::str_to_lower : &TextType::str_to_upper);
10706
10707
10707
10708
if (value->isBlob ())
@@ -10716,21 +10717,23 @@ dsc* StrCaseNode::execute(thread_db* tdbb, jrd_req* request) const
10716
10717
blb* blob = blb::open (tdbb, tdbb->getRequest ()->req_transaction ,
10717
10718
reinterpret_cast <bid*>(value->dsc_address ));
10718
10719
10719
- HalfStaticArray<UCHAR, BUFFER_SMALL > buffer;
10720
+ HalfStaticArray<UCHAR, BUFFER_MEDIUM > buffer;
10720
10721
10721
10722
if (charSet->isMultiByte ())
10722
- buffer.getBuffer (blob->blb_length ); // alloc space to put entire blob in memory
10723
+ {
10724
+ // Alloc space to put entire blob in memory, with extra space for additional bytes when changing case.
10725
+ buffer.getBuffer (blob->blb_length / charSet->minBytesPerChar () * charSet->maxBytesPerChar ());
10726
+ }
10723
10727
10724
- blb* newBlob = blb::create (tdbb, tdbb->getRequest ()->req_transaction ,
10725
- &impure->vlu_misc .vlu_bid );
10728
+ blb* newBlob = blb::create (tdbb, tdbb->getRequest ()->req_transaction , &impure->vlu_misc .vlu_bid );
10726
10729
10727
10730
while (!(blob->blb_flags & BLB_eof))
10728
10731
{
10729
10732
SLONG len = blob->BLB_get_data (tdbb, buffer.begin (), buffer.getCapacity (), false );
10730
10733
10731
10734
if (len)
10732
10735
{
10733
- len = (textType->*intlFunction)(len, buffer.begin (), len , buffer.begin ());
10736
+ len = (textType->*intlFunction)(len, buffer.begin (), buffer. getCapacity () , buffer.begin ());
10734
10737
newBlob->BLB_put_data (tdbb, buffer.begin (), len);
10735
10738
}
10736
10739
}
@@ -10743,16 +10746,16 @@ dsc* StrCaseNode::execute(thread_db* tdbb, jrd_req* request) const
10743
10746
UCHAR* ptr;
10744
10747
VaryStr<TEMP_STR_LENGTH> temp;
10745
10748
USHORT ttype;
10749
+ ULONG len = MOV_get_string_ptr (tdbb, value, &ttype, &ptr, &temp, sizeof (temp));
10746
10750
10747
10751
dsc desc;
10748
- desc.dsc_length = MOV_get_string_ptr (tdbb, value, &ttype, &ptr, &temp, sizeof (temp) );
10752
+ desc.dsc_length = len / charSet-> minBytesPerChar () * charSet-> maxBytesPerChar ( );
10749
10753
desc.dsc_dtype = dtype_text;
10750
10754
desc.dsc_address = NULL ;
10751
10755
desc.setTextType (ttype);
10752
10756
EVL_make_value (tdbb, &desc, impure);
10753
10757
10754
- ULONG len = (textType->*intlFunction)(desc.dsc_length ,
10755
- ptr, desc.dsc_length , impure->vlu_desc .dsc_address );
10758
+ len = (textType->*intlFunction)(len, ptr, desc.dsc_length , impure->vlu_desc .dsc_address );
10756
10759
10757
10760
if (len == INTL_BAD_STR_LENGTH)
10758
10761
status_exception::raise (Arg::Gds (isc_arith_except));
0 commit comments