The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=e26f3836d4e129c77e28854e9f84874a92723ac2

commit e26f3836d4e129c77e28854e9f84874a92723ac2
Author:     Konstantin Belousov <k...@freebsd.org>
AuthorDate: 2025-05-31 22:51:20 +0000
Commit:     Konstantin Belousov <k...@freebsd.org>
CommitDate: 2025-06-03 02:47:38 +0000

    kdump(1): Use static array for header types string literals
    
    Also change sprintf() to snprintf().
    
    Reviewed by:    brooks
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D50633
---
 usr.bin/kdump/kdump.c | 73 +++++++++++++++++----------------------------------
 1 file changed, 24 insertions(+), 49 deletions(-)

diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c
index d45a0cba2005..a8f3df14f304 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -663,6 +663,25 @@ dumptimespec(struct ktr_header *kth)
        }
 }
 
+static const char * const hdr_names[] = {
+       [KTR_SYSCALL] =         "CALL",
+       [KTR_SYSRET] =          "RET ",
+       [KTR_NAMEI] =           "NAMI",
+       [KTR_GENIO] =           "GIO ",
+       [KTR_PSIG] =            "PSIG",
+       [KTR_CSW] =             "CSW ",
+       [KTR_USER] =            "USER",
+       [KTR_STRUCT] =          "STRU",
+       [KTR_STRUCT_ARRAY] =    "STRU",
+       [KTR_SYSCTL] =          "SCTL",
+       [KTR_CAPFAIL] =         "CAP ",
+       [KTR_FAULT] =           "PFLT",
+       [KTR_FAULTEND] =        "PRET",
+       [KTR_ARGS] =            "ARGS",
+       [KTR_ENVS] =            "ENVS",
+       [KTR_EXTERR] =          "EERR",
+};
+
 static void
 dumpheader(struct ktr_header *kth, u_int sv_flags)
 {
@@ -671,56 +690,12 @@ dumpheader(struct ktr_header *kth, u_int sv_flags)
        const char *arch;
        const char *type;
 
-       switch (kth->ktr_type) {
-       case KTR_SYSCALL:
-               type = "CALL";
-               break;
-       case KTR_SYSRET:
-               type = "RET ";
-               break;
-       case KTR_NAMEI:
-               type = "NAMI";
-               break;
-       case KTR_GENIO:
-               type = "GIO ";
-               break;
-       case KTR_PSIG:
-               type = "PSIG";
-               break;
-       case KTR_CSW:
-               type = "CSW ";
-               break;
-       case KTR_USER:
-               type = "USER";
-               break;
-       case KTR_STRUCT:
-       case KTR_STRUCT_ARRAY:
-               type = "STRU";
-               break;
-       case KTR_SYSCTL:
-               type = "SCTL";
-               break;
-       case KTR_CAPFAIL:
-               type = "CAP ";
-               break;
-       case KTR_FAULT:
-               type = "PFLT";
-               break;
-       case KTR_FAULTEND:
-               type = "PRET";
-               break;
-       case KTR_ARGS:
-               type = "ARGS";
-               break;
-       case KTR_ENVS:
-               type = "ENVS";
-               break;
-       case KTR_EXTERR:
-               type = "EERR";
-               break;
-       default:
-               sprintf(unknown, "UNKNOWN(%d)", kth->ktr_type);
+       if (kth->ktr_type < 0 || (size_t)kth->ktr_type >= nitems(hdr_names)) {
+               snprintf(unknown, sizeof(unknown), "UNKNOWN(%d)",
+                   kth->ktr_type);
                type = unknown;
+       } else {
+               type = hdr_names[kth->ktr_type];
        }
 
        /*

Reply via email to