Skip to content

Commit

Permalink
cras: alsa: convert strncpy to strlcpy
Browse files Browse the repository at this point in the history
Removes the need for the -1 offset as it guarantees a null terminator

BUG=None
TEST=None

Change-Id: I8978b2d80b5c45b493dd9a65d5b12aeb156ae580
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5171140
Tested-by: Curtis Malainey <cujomalainey@chromium.org>
Commit-Queue: Baili Deng <bailideng@google.com>
Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com <chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com>
Auto-Submit: Curtis Malainey <cujomalainey@chromium.org>
Reviewed-by: Baili Deng <bailideng@google.com>
  • Loading branch information
cujomalainey authored and Chromeos LUCI committed Jan 8, 2024
1 parent 59ee11b commit ac23af3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions cras/src/server/cras_alsa_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,10 +924,10 @@ static void set_node_initial_state(struct cras_ionode* node,
if (endswith(node->name, "Jack") && !strstr(node->name, HDMI)) {
if (node->dev->direction == CRAS_STREAM_OUTPUT) {
node->type = CRAS_NODE_TYPE_HEADPHONE;
strncpy(node->name, HEADPHONE, sizeof(node->name) - 1);
strlcpy(node->name, HEADPHONE, sizeof(node->name));
} else {
node->type = CRAS_NODE_TYPE_MIC;
strncpy(node->name, MIC, sizeof(node->name) - 1);
strlcpy(node->name, MIC, sizeof(node->name));
}
}
if (strstr(node->name, HDMI) &&
Expand Down Expand Up @@ -1113,8 +1113,8 @@ static struct alsa_output_node* new_output(struct alsa_io* aio,
}
output->mixer_output = cras_control;

strncpy(output->base.name, name, sizeof(output->base.name) - 1);
strncpy(output->base.ucm_name, name, sizeof(output->base.ucm_name) - 1);
strlcpy(output->base.name, name, sizeof(output->base.name));
strlcpy(output->base.ucm_name, name, sizeof(output->base.ucm_name));
set_node_initial_state(&output->base, aio->common.card_type);
cras_iodev_add_node(&aio->common.base, &output->base);
check_auto_unplug_output_node(aio, &output->base, output->base.plugged);
Expand Down Expand Up @@ -1178,8 +1178,8 @@ static struct alsa_input_node* new_input(struct alsa_io* aio,
input->base.btflags |= CRAS_BT_FLAG_SCO_OFFLOAD;
}
input->mixer_input = cras_input;
strncpy(input->base.name, name, sizeof(input->base.name) - 1);
strncpy(input->base.ucm_name, name, sizeof(input->base.ucm_name) - 1);
strlcpy(input->base.name, name, sizeof(input->base.name));
strlcpy(input->base.ucm_name, name, sizeof(input->base.ucm_name));
set_node_initial_state(&input->base, aio->common.card_type);
set_input_default_node_gain(input, aio);
set_input_node_intrinsic_sensitivity(input, aio);
Expand Down
8 changes: 4 additions & 4 deletions cras/src/server/cras_alsa_usb_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,8 @@ static struct alsa_usb_output_node* usb_new_output(
}
output->mixer_output = cras_control;

strncpy(output->base.name, name, sizeof(output->base.name) - 1);
strncpy(output->base.ucm_name, name, sizeof(output->base.ucm_name) - 1);
strlcpy(output->base.name, name, sizeof(output->base.name));
strlcpy(output->base.ucm_name, name, sizeof(output->base.ucm_name));
usb_set_node_initial_state(&output->base);

cras_iodev_add_node(&aio->common.base, &output->base);
Expand Down Expand Up @@ -859,8 +859,8 @@ static struct alsa_usb_input_node* usb_new_input(
input->base.stable_id =
SuperFastHash(name, strlen(name), aio->common.base.info.stable_id);
input->mixer_input = cras_input;
strncpy(input->base.name, name, sizeof(input->base.name) - 1);
strncpy(input->base.ucm_name, name, sizeof(input->base.ucm_name) - 1);
strlcpy(input->base.name, name, sizeof(input->base.name));
strlcpy(input->base.ucm_name, name, sizeof(input->base.ucm_name));
usb_set_node_initial_state(&input->base);
usb_set_input_default_node_gain(input, aio);
usb_set_input_node_intrinsic_sensitivity(input, aio);
Expand Down

0 comments on commit ac23af3

Please sign in to comment.