]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
term/serial: Use grub_strncpy() instead of grub_snprintf() when only copying string
authorGlenn Washburn <development@efficientek.com>
Wed, 28 Jun 2023 07:47:09 +0000 (02:47 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 3 Jul 2023 12:07:49 +0000 (14:07 +0200)
Using grub_strncpy() instead of grub_snprintf() is less overhead and
indicates clearly that the dest should be the same string as the source.

Also fix indentation.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/term/serial.c

index 69fc0600f622e31e2f8e7ec403b339d27f6b4a73..8695554301535f703f56f734beaa4633c47dc217 100644 (file)
@@ -257,10 +257,10 @@ grub_cmd_serial (grub_extcmd_context_t ctxt, int argc, char **args)
     {
       if (grub_strncmp (state[OPTION_PORT].arg, "mmio,", sizeof ("mmio,") - 1) == 0 ||
          grub_strncmp (state[OPTION_PORT].arg, "pci,", sizeof ("pci,") - 1) == 0)
-          grub_snprintf (pname, sizeof (pname), "%s", state[1].arg);
+       grub_strncpy (pname, state[1].arg, sizeof (pname));
       else
-          grub_snprintf (pname, sizeof (pname), "port%lx",
-                         grub_strtoul (state[1].arg, 0, 0));
+       grub_snprintf (pname, sizeof (pname), "port%lx",
+                      grub_strtoul (state[1].arg, 0, 0));
       name = pname;
     }