[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 18/22] acpi: remove strzcpy (strncpy-identical) func
From: |
Jim Meyering |
Subject: |
[Qemu-devel] [PATCH 18/22] acpi: remove strzcpy (strncpy-identical) function; just use strncpy |
Date: |
Wed, 9 May 2012 11:24:02 +0200 |
From: Jim Meyering <address@hidden>
Adjust all uses s/strzcpy/strncpy/ and mark these uses
of strncpy as "ok".
Signed-off-by: Jim Meyering <address@hidden>
---
hw/acpi.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/hw/acpi.c b/hw/acpi.c
index 5d521e5..45ab345 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -60,18 +60,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)
{
@@ -156,7 +144,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;
}
@@ -186,12 +175,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;
}
@@ -206,7 +197,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;
}
--
1.7.10.1.487.ga3935e6
- [Qemu-devel] strncpy: best avoided (resend), Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 09/22] ui/vnc: simplify and avoid strncpy, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 10/22] bt: replace fragile snprintf use and unwarranted strncpy, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 12/22] virtio-9p: avoid unwarranted use of strncpy, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 06/22] os-posix: avoid buffer overrun, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 01/22] block: avoid buffer overrun by using pstrcpy, not strncpy, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 18/22] acpi: remove strzcpy (strncpy-identical) function; just use strncpy,
Jim Meyering <=
- [Qemu-devel] [PATCH 22/22] doc: update HACKING wrt strncpy/pstrcpy, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 11/22] virtio-9p: avoid unwarranted uses of strncpy, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 17/22] libcacard/vcard_emul_nss: use pstrcpy in place of strncpy, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 16/22] qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 15/22] target-i386: use pstrcpy, not strncpy, Jim Meyering, 2012/05/09