]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/fields.c: change_field(): Use a VLA
authorAlejandro Colomar <alx@kernel.org>
Mon, 12 Aug 2024 00:57:18 +0000 (02:57 +0200)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Mon, 16 Mar 2026 11:12:58 +0000 (12:12 +0100)
This allows using countof(), which is safer than a decoupled use of
the variable containing the length of the array.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/fields.c

index 144e5fd09afcdbf7d9ec6229d6596256aa5394df..f416b54f80c645c1f9e99198b222ef5f66960f4e 100644 (file)
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/param.h>
 
 #include "prototypes.h"
+#include "sizeof.h"
 #include "string/ctype/strisascii/strisprint.h"
 #include "string/ctype/strchrisascii/strchriscntrl.h"
 #include "string/strcmp/streq.h"
@@ -60,16 +62,12 @@ valid_field_(const char *field, const char *illegal)
 void
 change_field(char *buf, size_t maxsize, const char *prompt)
 {
-       char newf[200];
        char *cp;
-
-       if (maxsize > sizeof(newf)) {
-               maxsize = sizeof(newf);
-       }
+       char  newf[MIN(200, maxsize)];
 
        printf ("\t%s [%s]: ", prompt, buf);
        (void) fflush (stdout);
-       if (fgets(newf, maxsize, stdin) == NULL)
+       if (fgets(newf, countof(newf), stdin) == NULL)
                return;
 
        if (stpsep(newf, "\n") == NULL)