mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Fix potential missing '\0' when wrapping to legacy
The HAL API for port name is a C++ string of arbitrary length. Nevertheless the legacy API name had a maximum length. Thus when wrapping from the new to legacy, the string was truncated but no '\0' was added. Bug: 38184704 Test: compile Change-Id: I482363809718281e022041c2d5042e5800c5a617 Merged-In: I482363809718281e022041c2d5042e5800c5a617 Cherry-picked from master Signed-off-by: Kevin Rocard <krocard@google.com>
This commit is contained in:
@@ -296,8 +296,8 @@ void HidlUtils::audioPortToHal(const AudioPort& port, struct audio_port* halPort
|
||||
halPort->id = port.id;
|
||||
halPort->role = static_cast<audio_port_role_t>(port.role);
|
||||
halPort->type = static_cast<audio_port_type_t>(port.type);
|
||||
memcpy(halPort->name, port.name.c_str(),
|
||||
std::min(port.name.size(), static_cast<size_t>(AUDIO_PORT_MAX_NAME_LEN)));
|
||||
strncpy(halPort->name, port.name.c_str(), AUDIO_PORT_MAX_NAME_LEN);
|
||||
halPort->name[AUDIO_PORT_MAX_NAME_LEN - 1] = '\0';
|
||||
halPort->num_sample_rates =
|
||||
std::min(port.sampleRates.size(), static_cast<size_t>(AUDIO_PORT_MAX_SAMPLING_RATES));
|
||||
for (size_t i = 0; i < halPort->num_sample_rates; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user