@@ -118,7 +118,7 @@ QirArray::QirArray(TItemCount countItems, TItemSize itemSizeBytes, TDimCount dim
118118
119119 assert (this ->count * (TBufSize)itemSizeInBytes < std::numeric_limits<TBufSize>::max ());
120120 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
121- const TBufSize bufferSize = this ->count * itemSizeInBytes;
121+ const TBufSize bufferSize = (TBufSize) this ->count * (TBufSize) itemSizeInBytes;
122122 if (bufferSize > 0 )
123123 {
124124 this ->buffer = new char [bufferSize];
@@ -146,7 +146,7 @@ QirArray::QirArray(const QirArray& other)
146146
147147 assert ((TBufSize)(this ->count ) * this ->itemSizeInBytes < std::numeric_limits<TBufSize>::max ());
148148 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
149- const TBufSize size = this ->count * this ->itemSizeInBytes ;
149+ const TBufSize size = (TBufSize) this ->count * (TBufSize) this ->itemSizeInBytes ;
150150 if (this ->count > 0 )
151151 {
152152 this ->buffer = new char [size];
@@ -167,7 +167,7 @@ QirArray::~QirArray()
167167char * QirArray::GetItemPointer (TItemCount index) const
168168{
169169 assert (index < this ->count );
170- return &this ->buffer [index * this ->itemSizeInBytes ];
170+ return &this ->buffer [static_cast <TBufSize>( index * this ->itemSizeInBytes ) ];
171171}
172172
173173void QirArray::Append (const QirArray* other)
@@ -178,7 +178,7 @@ void QirArray::Append(const QirArray* other)
178178
179179 assert ((TBufSize)(other->count ) * other->itemSizeInBytes < std::numeric_limits<TBufSize>::max ());
180180 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
181- const TBufSize otherSize = other->count * other->itemSizeInBytes ;
181+ const TBufSize otherSize = (TBufSize) other->count * (TBufSize) other->itemSizeInBytes ;
182182
183183 if (otherSize == 0 )
184184 {
@@ -187,7 +187,7 @@ void QirArray::Append(const QirArray* other)
187187
188188 assert ((TBufSize)(this ->count ) * this ->itemSizeInBytes < std::numeric_limits<TBufSize>::max ());
189189 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
190- const TBufSize thisSize = this ->count * this ->itemSizeInBytes ;
190+ const TBufSize thisSize = (TBufSize) this ->count * (TBufSize) this ->itemSizeInBytes ;
191191
192192 char * newBuffer = new char [thisSize + otherSize];
193193 if (thisSize)
@@ -585,14 +585,16 @@ extern "C"
585585 assert ((QirArray::TBufSize)rangeRunCount * itemSizeInBytes <
586586 std::numeric_limits<QirArray::TBufSize>::max ());
587587 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
588- const QirArray::TBufSize rangeChunkSize = rangeRunCount * itemSizeInBytes;
588+ const QirArray::TBufSize rangeChunkSize =
589+ (QirArray::TBufSize)rangeRunCount * (QirArray::TBufSize)itemSizeInBytes;
589590
590591 QirArray::TItemCount dst = 0 ;
591592 QirArray::TItemCount src = (QirArray::TItemCount)(singleIndexRunCount * range.start );
592593 while (src < array->count )
593594 {
594595 assert (dst < slice->count );
595- memcpy (&slice->buffer [dst * itemSizeInBytes], &array->buffer [src * itemSizeInBytes], rangeChunkSize);
596+ memcpy (&slice->buffer [static_cast <QirArray::TBufSize>(dst * itemSizeInBytes)],
597+ &array->buffer [static_cast <QirArray::TBufSize>(src * itemSizeInBytes)], rangeChunkSize);
596598 src += rowCount;
597599 dst += rangeRunCount;
598600 }
@@ -603,22 +605,25 @@ extern "C"
603605 assert ((QirArray::TBufSize)singleIndexRunCount * itemSizeInBytes <
604606 std::numeric_limits<QirArray::TBufSize>::max ());
605607 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
606- const QirArray::TBufSize chunkSize = singleIndexRunCount * itemSizeInBytes;
607- QirArray::TItemCount dst = 0 ;
608- QirArray::TItemCount src = (QirArray::TItemCount)(singleIndexRunCount * range.start );
608+ const QirArray::TBufSize chunkSize =
609+ (QirArray::TBufSize)singleIndexRunCount * (QirArray::TBufSize)itemSizeInBytes;
610+ QirArray::TItemCount dst = 0 ;
611+ QirArray::TItemCount src = (QirArray::TItemCount)(singleIndexRunCount * range.start );
609612 while (src < array->count )
610613 {
611614 assert (dst < slice->count );
612615
613616 int64_t srcInner = src; // The `srcInner` can go negative in the end of the last iteration.
614617 for (int64_t index = range.start ; index != range.end ; index += range.step )
615618 {
616- assert ((dst * itemSizeInBytes + chunkSize) <= (slice->count * slice->itemSizeInBytes ));
619+ assert (((QirArray::TItemSize)dst * itemSizeInBytes + (QirArray::TItemSize)chunkSize) <=
620+ (QirArray::TItemSize)slice->count * slice->itemSizeInBytes );
617621 assert ((srcInner * (int64_t )itemSizeInBytes + (int64_t )chunkSize) <=
618- (array->count * array->itemSizeInBytes ));
622+ (( int64_t ) array->count * ( int64_t ) array->itemSizeInBytes ));
619623 assert (srcInner >= 0 );
620624
621- memcpy (&slice->buffer [dst * itemSizeInBytes], &array->buffer [srcInner * itemSizeInBytes], chunkSize);
625+ memcpy (&slice->buffer [static_cast <QirArray::TBufSize>(dst * itemSizeInBytes)],
626+ &array->buffer [static_cast <QirArray::TBufSize>(srcInner * itemSizeInBytes)], chunkSize);
622627 srcInner += (singleIndexRunCount * range.step );
623628 dst += singleIndexRunCount;
624629 }
@@ -660,14 +665,16 @@ extern "C"
660665 std::numeric_limits<QirArray::TBufSize>::max ());
661666 // Using `<` rather than `<=` to calm down the compiler on 32-bit arch.
662667
663- const QirArray::TBufSize chunkSize = singleIndexRunCount * itemSizeInBytes;
668+ const QirArray::TBufSize chunkSize =
669+ (QirArray::TBufSize)singleIndexRunCount * (QirArray::TBufSize)itemSizeInBytes;
664670
665671 QirArray::TItemCount dst = 0 ;
666672 QirArray::TItemCount src = (QirArray::TItemCount)(singleIndexRunCount * index);
667673 while (src < array->count )
668674 {
669675 assert (dst < project->count );
670- memcpy (&project->buffer [dst * itemSizeInBytes], &array->buffer [src * itemSizeInBytes], chunkSize);
676+ memcpy (&project->buffer [static_cast <QirArray::TBufSize>(dst * itemSizeInBytes)],
677+ &array->buffer [static_cast <QirArray::TBufSize>(src * itemSizeInBytes)], chunkSize);
671678 src += rowCount;
672679 dst += singleIndexRunCount;
673680 }
0 commit comments