diff --git a/Storage/MassStorage/SCSI/Target.hpp b/Storage/MassStorage/SCSI/Target.hpp index 99bd5d9c2..e75baec4f 100644 --- a/Storage/MassStorage/SCSI/Target.hpp +++ b/Storage/MassStorage/SCSI/Target.hpp @@ -278,12 +278,12 @@ struct Executor { }; auto copy_string = [] (uint8_t *destination, const char *source, size_t length) -> void { - // Copy as much of the string as will fit, and pad with spaces. - uint8_t *end = reinterpret_cast(strncpy(reinterpret_cast(destination), source, length)); - while(end < destination + length) { - *end = ' '; - ++end; - } + // Determine length of source and copy in as much as possible. + const auto source_length = std::min(strlen(source), length); + memcpy(destination, source, source_length); + + // Fill the rest with spaces. + memset(&destination[source_length], ' ', length - source_length); }; copy_string(&response[8], inq.vendor_identifier, 8); copy_string(&response[16], inq.product_identifier, 16);