Skip to content

Commit daf0611

Browse files
committed
fixes
1 parent 5e3fce6 commit daf0611

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

quaddtype/numpy_quaddtype/src/casts.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
579563
template <bool Aligned>
580564
static int
581565
quad_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

Comments
 (0)