| 503 | |
| 504 | |
| 505 | ULONG EngineCallbacks::validateLength(CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start, |
| 506 | const USHORT size) |
| 507 | { |
| 508 | fb_assert(charSet); |
| 509 | |
| 510 | if (charSet && (charSet->isMultiByte() || length > size)) |
| 511 | { |
| 512 | const ULONG srcCharLength = charSet->length(length, start, true); |
| 513 | const ULONG destCharLength = (ULONG) size / charSet->maxBytesPerChar(); |
| 514 | |
| 515 | if (srcCharLength > destCharLength) |
| 516 | { |
| 517 | const ULONG spaceByteLength = charSet->getSpaceLength(); |
| 518 | const ULONG trimmedByteLength = charSet->removeTrailingSpaces(length, start); |
| 519 | const ULONG trimmedCharLength = srcCharLength - (length - trimmedByteLength) / spaceByteLength; |
| 520 | |
| 521 | if (trimmedCharLength <= destCharLength) |
| 522 | return trimmedByteLength + (destCharLength - trimmedCharLength) * spaceByteLength; |
| 523 | else |
| 524 | { |
| 525 | err(Arg::Gds(isc_arith_except) << Arg::Gds(isc_string_truncation) << |
| 526 | Arg::Gds(isc_trunc_limits) << Arg::Num(destCharLength) << Arg::Num(srcCharLength)); |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | return length; |
| 532 | } |
| 533 | |
| 534 | |
| 535 | ULONG TruncateCallbacks::validateLength(CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start, |
no test coverage detected