@@ -67,7 +67,9 @@ multiply_resolve_descriptors(
6767 } \
6868 } \
6969 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 ; \
7173 \
7274 if (npy_string_newemptysize (newsize , os ) < 0 ) { \
7375 gil_error (PyExc_MemoryError , \
@@ -76,7 +78,8 @@ multiply_resolve_descriptors(
7678 } \
7779 \
7880 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 ); \
8083 } \
8184 \
8285 sin += s_stride ; \
@@ -215,7 +218,6 @@ add_strided_loop(PyArrayMethod_Context *context, char *const data[],
215218 npy_static_string * os = NULL ;
216219
217220 while (N -- ) {
218- int newsize = 0 ;
219221 s1 = (npy_static_string * )in1 ;
220222 s2 = (npy_static_string * )in2 ;
221223 int s1_isnull = npy_string_isnull (s1 );
@@ -240,13 +242,20 @@ add_strided_loop(PyArrayMethod_Context *context, char *const data[],
240242 "Cannot add null that is not a nan-like value" );
241243 }
242244 }
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 ) {
245250 return -1 ;
246251 }
247252
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 );
250259
251260 next_step :
252261 in1 += in1_stride ;
@@ -385,7 +394,11 @@ string_equal_strided_loop(PyArrayMethod_Context *context, char *const data[],
385394 }
386395 }
387396 }
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 ) {
389402 * out = (npy_bool )1 ;
390403 }
391404 else {
@@ -450,7 +463,14 @@ string_not_equal_strided_loop(PyArrayMethod_Context *context,
450463 }
451464 }
452465 }
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 ) {
454474 * out = (npy_bool )0 ;
455475 }
456476 else {
0 commit comments