@@ -460,7 +460,6 @@ bytes_to_quad_convert(const char *bytes_str, npy_intp bytes_size,
460460 }
461461
462462 memcpy (temp_str, bytes_str, bytes_size);
463- temp_str[bytes_size] = ' \0 ' ;
464463
465464 // Find the actual end (null byte or first occurrence)
466465 npy_intp actual_len = 0 ;
@@ -561,21 +560,6 @@ quad_to_bytes_resolve_descriptors(PyObject *NPY_UNUSED(self), PyArray_DTypeMeta
561560 return NPY_SAME_KIND_CASTING;
562561}
563562
564- // Helper function: Copy string to bytes output buffer
565- static inline void
566- copy_string_to_bytes (const char *str, char *out_bytes, npy_intp bytes_size)
567- {
568- npy_intp str_len = strlen (str);
569-
570- npy_intp copy_len = (str_len < bytes_size) ? str_len : bytes_size;
571- memcpy (out_bytes, str, copy_len);
572-
573- // Pad remaining space with null bytes
574- for (npy_intp i = copy_len; i < bytes_size; i++) {
575- out_bytes[i] = ' \0 ' ;
576- }
577- }
578-
579563template <bool Aligned>
580564static int
581565quad_to_bytes_loop (PyArrayMethod_Context *context, char *const data[],
@@ -607,7 +591,8 @@ quad_to_bytes_loop(PyArrayMethod_Context *context, char *const data[],
607591 return -1 ;
608592 }
609593
610- copy_string_to_bytes (temp_str, out_ptr, bytes_size);
594+ // Copy string to output buffer, padding with nulls
595+ strncpy (out_ptr, temp_str, bytes_size);
611596
612597 Py_DECREF (py_str);
613598
0 commit comments