@@ -67,7 +67,9 @@ multiply_resolve_descriptors(
67
67
} \
68
68
} \
69
69
npy_ ##shortname factor = *(npy_##shortname *)iin; \
70
- size_t newsize = (size_t)((is->size) * factor); \
70
+ size_t cursize = npy_string_size(is); \
71
+ /* FIXME: check for overflow? */ \
72
+ size_t newsize = cursize * factor ; \
71
73
\
72
74
if (npy_string_newemptysize (newsize , os ) < 0 ) { \
73
75
gil_error (PyExc_MemoryError , \
@@ -76,7 +78,8 @@ multiply_resolve_descriptors(
76
78
} \
77
79
\
78
80
for (size_t i = 0 ; i < (size_t )factor ; i ++ ) { \
79
- memcpy(os->buf + i * is->size, is->buf, is->size); \
81
+ memcpy (npy_string_buf (os ) + i * cursize , npy_string_buf (is ), \
82
+ cursize ); \
80
83
} \
81
84
\
82
85
sin += s_stride ; \
@@ -215,7 +218,6 @@ add_strided_loop(PyArrayMethod_Context *context, char *const data[],
215
218
npy_static_string * os = NULL ;
216
219
217
220
while (N -- ) {
218
- int newsize = 0 ;
219
221
s1 = (npy_static_string * )in1 ;
220
222
s2 = (npy_static_string * )in2 ;
221
223
int s1_isnull = npy_string_isnull (s1 );
@@ -240,13 +242,20 @@ add_strided_loop(PyArrayMethod_Context *context, char *const data[],
240
242
"Cannot add null that is not a nan-like value" );
241
243
}
242
244
}
243
- newsize = s1 -> size + s2 -> size ;
244
- if (npy_string_newemptysize (newsize , os ) < 0 ) {
245
+
246
+ size_t s1_size = npy_string_size (s1 );
247
+ size_t s2_size = npy_string_size (s2 );
248
+
249
+ if (npy_string_newemptysize (s1_size + s2_size , os ) < 0 ) {
245
250
return -1 ;
246
251
}
247
252
248
- memcpy (os -> buf , s1 -> buf , s1 -> size );
249
- memcpy (os -> buf + s1 -> size , s2 -> buf , s2 -> size );
253
+ char * os_buf = npy_string_buf (os );
254
+ char * s1_buf = npy_string_buf (s1 );
255
+ char * s2_buf = npy_string_buf (s2 );
256
+
257
+ memcpy (os_buf , s1_buf , s1_size );
258
+ memcpy (os_buf + s1_size , s2_buf , s2_size );
250
259
251
260
next_step :
252
261
in1 += in1_stride ;
@@ -385,7 +394,11 @@ string_equal_strided_loop(PyArrayMethod_Context *context, char *const data[],
385
394
}
386
395
}
387
396
}
388
- if (s1 -> size == s2 -> size && strncmp (s1 -> buf , s2 -> buf , s1 -> size ) == 0 ) {
397
+ char * s1_buf = npy_string_buf (s1 );
398
+ char * s2_buf = npy_string_buf (s2 );
399
+ size_t s1_size = npy_string_size (s1 );
400
+ size_t s2_size = npy_string_size (s2 );
401
+ if (s1_size == s2_size && strncmp (s1_buf , s2_buf , s1_size ) == 0 ) {
389
402
* out = (npy_bool )1 ;
390
403
}
391
404
else {
@@ -450,7 +463,14 @@ string_not_equal_strided_loop(PyArrayMethod_Context *context,
450
463
}
451
464
}
452
465
}
453
- if (s1 -> size == s2 -> size && strncmp (s1 -> buf , s2 -> buf , s1 -> size ) == 0 ) {
466
+
467
+ size_t s1_size = npy_string_size (s1 );
468
+ size_t s2_size = npy_string_size (s2 );
469
+
470
+ char * s1_buf = npy_string_buf (s1 );
471
+ char * s2_buf = npy_string_buf (s2 );
472
+
473
+ if (s1_size == s2_size && strncmp (s1_buf , s2_buf , s1_size ) == 0 ) {
454
474
* out = (npy_bool )0 ;
455
475
}
456
476
else {
0 commit comments