@@ -292,7 +292,8 @@ enum UdfError
292
292
static SSHORT blob_get_segment(blb*, UCHAR*, USHORT, USHORT*);
293
293
static void blob_put_segment(blb*, const UCHAR*, USHORT);
294
294
static SLONG blob_lseek(blb*, USHORT, SLONG);
295
- static SLONG get_scalar_array(const Parameter*, DSC*, scalar_array_desc*, UCharStack&);
295
+ static ULONG get_scalar_array(thread_db* tdbb, const Parameter*, DSC*,
296
+ scalar_array_desc*, UCharStack&);
296
297
static void invoke(thread_db* tdbb,
297
298
const Function* function,
298
299
const Parameter* return_ptr,
@@ -436,8 +437,7 @@ void FUN_evaluate(thread_db* tdbb, const Function* function, const NestValueArra
436
437
437
438
temp_desc = parameter->prm_desc;
438
439
temp_desc.dsc_address = temp_ptr;
439
- // CVC: There's a theoretical possibility of overflowing "length" here.
440
- USHORT length = FB_ALIGN(temp_desc.dsc_length, FB_DOUBLE_ALIGN);
440
+ ULONG length = FB_ALIGN(temp_desc.dsc_length, FB_DOUBLE_ALIGN);
441
441
442
442
// If we've got a null argument, just pass zeros (got any better ideas?)
443
443
@@ -446,7 +446,7 @@ void FUN_evaluate(thread_db* tdbb, const Function* function, const NestValueArra
446
446
if (parameter->prm_fun_mechanism == FUN_value)
447
447
{
448
448
UCHAR* p = (UCHAR *) arg_ptr;
449
- MOVE_CLEAR(p, (SLONG) length);
449
+ MOVE_CLEAR(p, length);
450
450
p += length;
451
451
arg_ptr = reinterpret_cast<UDF_ARG*>(p);
452
452
continue;
@@ -458,7 +458,7 @@ void FUN_evaluate(thread_db* tdbb, const Function* function, const NestValueArra
458
458
}
459
459
460
460
if (parameter->prm_fun_mechanism != FUN_ref_with_null)
461
- MOVE_CLEAR(temp_ptr, (SLONG) length);
461
+ MOVE_CLEAR(temp_ptr, length);
462
462
else
463
463
{
464
464
// Probably for arrays and blobs it's better to preserve the
@@ -468,7 +468,7 @@ void FUN_evaluate(thread_db* tdbb, const Function* function, const NestValueArra
468
468
case dtype_quad:
469
469
case dtype_array:
470
470
case dtype_blob:
471
- MOVE_CLEAR(temp_ptr, (SLONG) length);
471
+ MOVE_CLEAR(temp_ptr, length);
472
472
break;
473
473
default: // FUN_ref_with_null, non-blob, non-array: we send null pointer.
474
474
*arg_ptr++ = 0;
@@ -478,7 +478,8 @@ void FUN_evaluate(thread_db* tdbb, const Function* function, const NestValueArra
478
478
}
479
479
else if (parameter->prm_fun_mechanism == FUN_scalar_array)
480
480
{
481
- length = get_scalar_array(parameter, input, (scalar_array_desc*)temp_ptr, array_stack);
481
+ length = get_scalar_array(tdbb, parameter, input, (scalar_array_desc*) temp_ptr,
482
+ array_stack);
482
483
}
483
484
else
484
485
{
@@ -975,10 +976,11 @@ static SSHORT blob_get_segment(blb* blob, UCHAR* buffer, USHORT length, USHORT*
975
976
}
976
977
977
978
978
- static SLONG get_scalar_array(const Parameter* arg,
979
- DSC* value,
980
- scalar_array_desc* scalar_desc,
981
- UCharStack& stack)
979
+ static ULONG get_scalar_array(thread_db* tdbb,
980
+ const Parameter* arg,
981
+ DSC* value,
982
+ scalar_array_desc* scalar_desc,
983
+ UCharStack& stack)
982
984
{
983
985
/**************************************
984
986
*
@@ -992,17 +994,16 @@ static SLONG get_scalar_array(const Parameter* arg,
992
994
* Return length of array desc.
993
995
*
994
996
**************************************/
995
- thread_db* tdbb = JRD_get_thread_data ();
997
+ MemoryPool& pool = *tdbb->getDefaultPool ();
996
998
997
999
// Get first the array descriptor, then the array
998
1000
999
1001
SLONG stuff[IAD_LEN(16) / 4];
1000
1002
Ods::InternalArrayDesc* array_desc = (Ods::InternalArrayDesc*) stuff;
1001
- blb* blob = blb::get_array(tdbb, tdbb->getRequest()->req_transaction, (bid*)value->dsc_address,
1002
- array_desc);
1003
+ blb* blob = blb::get_array(tdbb, tdbb->getRequest()->req_transaction,
1004
+ (bid*) value->dsc_address, array_desc);
1003
1005
1004
- fb_assert(array_desc->iad_total_length >= 0); // check before upcasting to size_t
1005
- UCHAR* data = FB_NEW_POOL(*getDefaultMemoryPool()) UCHAR[static_cast<size_t>(array_desc->iad_total_length)];
1006
+ AutoPtr<UCHAR, ArrayDelete> data(FB_NEW_POOL(pool) UCHAR[array_desc->iad_total_length]);
1006
1007
blob->BLB_get_data(tdbb, data, array_desc->iad_total_length);
1007
1008
const USHORT dimensions = array_desc->iad_dimensions;
1008
1009
@@ -1012,39 +1013,29 @@ static SLONG get_scalar_array(const Parameter* arg,
1012
1013
dsc from = array_desc->iad_rpt[0].iad_desc;
1013
1014
1014
1015
if (to.dsc_dtype != from.dsc_dtype ||
1015
- to.dsc_scale != from.dsc_scale || to.dsc_length != from.dsc_length)
1016
+ to.dsc_scale != from.dsc_scale ||
1017
+ to.dsc_length != from.dsc_length)
1016
1018
{
1017
- SLONG n = array_desc->iad_count;
1018
- UCHAR* const temp = FB_NEW_POOL(*getDefaultMemoryPool()) UCHAR[static_cast<size_t>( to.dsc_length * n)] ;
1019
+ ULONG n = array_desc->iad_count;
1020
+ AutoPtr< UCHAR, ArrayDelete> temp( FB_NEW_POOL(pool) UCHAR[to.dsc_length * n]) ;
1019
1021
to.dsc_address = temp;
1020
1022
from.dsc_address = data;
1021
1023
1022
- // This loop may call ERR_post indirectly.
1023
- try
1024
- {
1025
- for (; n; --n, to.dsc_address += to.dsc_length,
1026
- from.dsc_address += array_desc->iad_element_length)
1027
- {
1028
- MOV_move(tdbb, &from, &to);
1029
- }
1030
- }
1031
- catch (const Exception&)
1024
+ for (; n; --n, to.dsc_address += to.dsc_length,
1025
+ from.dsc_address += array_desc->iad_element_length)
1032
1026
{
1033
- delete[] data;
1034
- delete[] temp;
1035
- throw;
1027
+ MOV_move(tdbb, &from, &to);
1036
1028
}
1037
1029
1038
- delete[] data;
1039
- data = temp;
1030
+ data = temp.release();
1040
1031
}
1041
1032
1042
1033
// Fill out the scalar array descriptor
1043
1034
1044
- stack.push(data);
1045
1035
scalar_desc->sad_desc = arg->prm_desc;
1046
1036
scalar_desc->sad_desc.dsc_address = data;
1047
1037
scalar_desc->sad_dimensions = dimensions;
1038
+ stack.push(data.release());
1048
1039
1049
1040
const Ods::InternalArrayDesc::iad_repeat* tail1 = array_desc->iad_rpt;
1050
1041
scalar_array_desc::sad_repeat* tail2 = scalar_desc->sad_rpt;
@@ -1055,7 +1046,8 @@ static SLONG get_scalar_array(const Parameter* arg,
1055
1046
tail2->sad_lower = tail1->iad_lower;
1056
1047
}
1057
1048
1058
- return static_cast<SLONG>(sizeof(scalar_array_desc) + (dimensions - 1u) * sizeof(scalar_array_desc::sad_repeat));
1049
+ return static_cast<ULONG>(sizeof(scalar_array_desc) +
1050
+ (dimensions - 1u) * sizeof(scalar_array_desc::sad_repeat));
1059
1051
}
1060
1052
1061
1053
0 commit comments