@@ -140,12 +140,11 @@ CUTEST_TEST_TEST(concatenate) {
140140 for (int i = 0 ; i < shapes .ndim ; ++ i ) {
141141 if (i == axis ) {
142142 helpershape [i ] = shapes .shape1 [i ] + shapes .shape2 [i ];
143- buffersize *= (size_t ) (shapes .shape1 [i ] + shapes .shape2 [i ]);
144143 }
145144 else {
146145 helpershape [i ] = shapes .shape1 [i ];
147- buffersize *= (size_t ) shapes .shape1 [i ];
148146 }
147+ buffersize *= helpershape [i ]; // Multiply by each dimension
149148 }
150149 // Allocate a buffer for the concatenated array
151150 uint8_t * helperbuffer = malloc (buffersize );
@@ -221,18 +220,20 @@ CUTEST_TEST_TEST(concatenate) {
221220
222221 // Set up the region to fill (corresponding to src2's position)
223222 for (int i = 0 ; i < shapes .ndim ; i ++ ) {
224- if (i == axis ) {
225- start_src2 [i ] = shapes .shape1 [i ]; // src2 starts after src1
226- stop_src2 [i ] = shapes .shape1 [i ] + shapes .shape2 [i ];
227- } else {
228- start_src2 [i ] = 0 ;
229- stop_src2 [i ] = shapes .shape2 [i ];
230- }
223+ if (i == axis ) {
224+ start_src2 [i ] = shapes .shape1 [i ]; // src2 starts after src1
225+ stop_src2 [i ] = shapes .shape1 [i ] + shapes .shape2 [i ];
226+ } else {
227+ start_src2 [i ] = 0 ;
228+ // Use the minimum of shape1 and shape2 for non-axis dimensions
229+ stop_src2 [i ] = (shapes .shape1 [i ] < shapes .shape2 [i ]) ?
230+ shapes .shape1 [i ] : shapes .shape2 [i ];
231+ }
231232 }
232233
233- // Fill the region with the value
234- fill_buffer_region (helperbuffer , helpershape , shapes .ndim ,
235- start_src2 , stop_src2 , value , typesize );
234+ // Fill the region with the value
235+ fill_buffer_region (helperbuffer , helpershape , shapes .ndim ,
236+ start_src2 , stop_src2 , value , typesize );
236237
237238 // Check the shape of the concatenated array
238239 for (int i = 0 ; i < ctx -> ndim ; ++ i ) {
@@ -259,13 +260,15 @@ CUTEST_TEST_TEST(concatenate) {
259260 int64_t start [B2ND_MAX_DIM ] = {0 };
260261 int64_t stop [B2ND_MAX_DIM ] = {0 };
261262 int64_t buffershape [B2ND_MAX_DIM ] = {0 };
263+ size_t elementcount = 1 ; // Count of elements
262264 for (int i = 0 ; i < ctx -> ndim ; ++ i ) {
263265 start [i ] = 0 ;
264266 stop [i ] = array -> shape [i ];
265267 buffershape [i ] = stop [i ] - start [i ];
266- buffersize *= buffershape [i ];
268+ elementcount *= buffershape [i ];
267269 }
268- uint8_t * buffer = malloc (buffersize );
270+ size_t buffersize2 = elementcount * typesize ;
271+ uint8_t * buffer = malloc (buffersize2 );
269272 B2ND_TEST_ASSERT (b2nd_get_slice_cbuffer (array , start , stop , buffer , buffershape , buffersize ));
270273 // Check if the data in the concatenated array matches the helperbuffer
271274 uint8_t * buffer_fill = malloc (typesize );
@@ -293,11 +296,11 @@ CUTEST_TEST_TEST(concatenate) {
293296 if (!is_true ) {
294297 // Print the raw byte values for better debugging
295298 fprintf (stderr , "Data mismatch at index %ld: buffer bytes = " , i );
296- for (int b = 0 ; b < typesize + 10 ; b ++ ) {
299+ for (int b = 0 ; b < typesize ; b ++ ) {
297300 fprintf (stderr , "%02x " , buffer [i * typesize + b ]);
298301 }
299302 fprintf (stderr , ", helperbuffer bytes = " );
300- for (int b = 0 ; b < typesize + 10 ; b ++ ) {
303+ for (int b = 0 ; b < typesize ; b ++ ) {
301304 fprintf (stderr , "%02x " , helperbuffer [i * typesize + b ]);
302305 }
303306 fprintf (stderr , "\n" );
0 commit comments