Skip to content

Commit

Permalink
acpi: remove strzcpy (strncpy-identical) function; just use strncpy
Browse files Browse the repository at this point in the history
Adjust all uses s/strzcpy/strncpy/ and mark these uses
of strncpy as "ok".

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
Jim Meyering authored and Anthony Liguori committed Oct 5, 2012
1 parent 2e67978 commit 3cda346
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions hw/acpi.c
Expand Up @@ -61,18 +61,6 @@ static int acpi_checksum(const uint8_t *data, int len)
return (-sum) & 0xff;
}

/* like strncpy() but zero-fills the tail of destination */
static void strzcpy(char *dst, const char *src, size_t size)
{
size_t len = strlen(src);
if (len >= size) {
len = size;
} else {
memset(dst + len, 0, size - len);
}
memcpy(dst, src, len);
}

/* XXX fixme: this function uses obsolete argument parsing interface */
int acpi_table_add(const char *t)
{
Expand Down Expand Up @@ -157,7 +145,8 @@ int acpi_table_add(const char *t)
hdr._length = cpu_to_le16(len);

if (get_param_value(buf, sizeof(buf), "sig", t)) {
strzcpy(hdr.sig, buf, sizeof(hdr.sig));
/* strncpy is justified: the field need not be NUL-terminated. */
strncpy(hdr.sig, buf, sizeof(hdr.sig));
++changed;
}

Expand Down Expand Up @@ -187,12 +176,14 @@ int acpi_table_add(const char *t)
}

if (get_param_value(buf, sizeof(buf), "oem_id", t)) {
strzcpy(hdr.oem_id, buf, sizeof(hdr.oem_id));
/* strncpy is justified: the field need not be NUL-terminated. */
strncpy(hdr.oem_id, buf, sizeof(hdr.oem_id));
++changed;
}

if (get_param_value(buf, sizeof(buf), "oem_table_id", t)) {
strzcpy(hdr.oem_table_id, buf, sizeof(hdr.oem_table_id));
/* strncpy is justified: the field need not be NUL-terminated. */
strncpy(hdr.oem_table_id, buf, sizeof(hdr.oem_table_id));
++changed;
}

Expand All @@ -207,7 +198,8 @@ int acpi_table_add(const char *t)
}

if (get_param_value(buf, sizeof(buf), "asl_compiler_id", t)) {
strzcpy(hdr.asl_compiler_id, buf, sizeof(hdr.asl_compiler_id));
/* strncpy is justified: the field need not be NUL-terminated. */
strncpy(hdr.asl_compiler_id, buf, sizeof(hdr.asl_compiler_id));
++changed;
}

Expand Down

0 comments on commit 3cda346

Please sign in to comment.