8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 12:03:02 +01:00

Better assertions, code simplification and minor optimization

This commit is contained in:
Dmitry Yemanov 2020-09-29 13:30:21 +03:00
parent 5a5a76c56d
commit a1c2fbc1c8

View File

@ -501,7 +501,7 @@ static void get_trigger_dependencies(DeferredWork*, bool, jrd_tra*);
static void load_trigs(thread_db*, jrd_rel*, TrigVector**); static void load_trigs(thread_db*, jrd_rel*, TrigVector**);
static Format* make_format(thread_db*, jrd_rel*, USHORT *, TemporaryField*); static Format* make_format(thread_db*, jrd_rel*, USHORT *, TemporaryField*);
static void put_summary_blob(thread_db* tdbb, blb*, enum rsr_t, bid*, jrd_tra*); static void put_summary_blob(thread_db* tdbb, blb*, enum rsr_t, bid*, jrd_tra*);
static void put_summary_record(thread_db* tdbb, blb*, enum rsr_t, const UCHAR*, USHORT); static void put_summary_record(thread_db* tdbb, blb*, enum rsr_t, const UCHAR*, ULONG);
static void setup_array(thread_db*, blb*, const TEXT*, USHORT, TemporaryField*); static void setup_array(thread_db*, blb*, const TEXT*, USHORT, TemporaryField*);
static blb* setup_triggers(thread_db*, jrd_rel*, bool, TrigVector**, blb*); static blb* setup_triggers(thread_db*, jrd_rel*, bool, TrigVector**, blb*);
static void setup_trigger_details(thread_db*, jrd_rel*, blb*, TrigVector**, const TEXT*, bool); static void setup_trigger_details(thread_db*, jrd_rel*, blb*, TrigVector**, const TEXT*, bool);
@ -6204,13 +6204,18 @@ static void put_summary_blob(thread_db* tdbb, blb* blob, rsr_t type, bid* blob_i
// Go ahead and open blob // Go ahead and open blob
blb* blr = blb::open(tdbb, transaction, blob_id); blb* blr = blb::open(tdbb, transaction, blob_id);
fb_assert(blr->blb_length <= MAX_USHORT);
USHORT length = (USHORT) blr->blb_length; ULONG length = blr->blb_length;
HalfStaticArray<UCHAR, 128> buffer; // We cannot deal with chunks longer than a max blob segment (minus one)
fb_assert(length < MAX_USHORT);
length = (USHORT) blr->BLB_get_data(tdbb, buffer.getBuffer(length), (SLONG) length); HalfStaticArray<UCHAR, BUFFER_TINY> buffer;
put_summary_record(tdbb, blob, type, buffer.begin(), length); UCHAR* p = buffer.getBuffer(length + 1);
*p++ = (UCHAR) type;
length = blr->BLB_get_data(tdbb, p, length);
blob->BLB_put_segment(tdbb, buffer.begin(), length + 1);
} }
@ -6218,7 +6223,7 @@ static void put_summary_record(thread_db* tdbb,
blb* blob, blb* blob,
rsr_t type, rsr_t type,
const UCHAR* data, const UCHAR* data,
USHORT length) ULONG length)
{ {
/************************************** /**************************************
* *
@ -6230,31 +6235,17 @@ static void put_summary_record(thread_db* tdbb,
* Put an attribute record to the relation summary blob. * Put an attribute record to the relation summary blob.
* *
**************************************/ **************************************/
// We cannot deal with chunks longer than a max blob segment (minus one)
fb_assert(length < MAX_USHORT);
SET_TDBB(tdbb); SET_TDBB(tdbb);
fb_assert(length < MAX_USHORT); // otherwise length + 1 wraps. Or do we bugcheck??? HalfStaticArray<UCHAR, BUFFER_TINY> buffer;
UCHAR temp[129]; UCHAR* p = buffer.getBuffer(length + 1);
UCHAR* const buffer = ((size_t) (length + 1) > sizeof(temp)) ?
FB_NEW_POOL(*getDefaultMemoryPool()) UCHAR[length + 1] : temp;
UCHAR* p = buffer;
*p++ = (UCHAR) type; *p++ = (UCHAR) type;
memcpy(p, data, length); memcpy(p, data, length);
try { blob->BLB_put_segment(tdbb, buffer.begin(), length + 1);
blob->BLB_put_segment(tdbb, buffer, length + 1);
}
catch (const Firebird::Exception&)
{
if (buffer != temp)
delete[] buffer;
throw;
}
if (buffer != temp)
delete[] buffer;
} }