]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Sat, 18 May 2024 23:53:12 +0000 (01:53 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 3 Jul 2024 15:03:12 +0000 (10:03 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
34 files changed:
contrib/adduser.c
lib/commonio.c
lib/console.c
lib/copydir.c
lib/fields.c
lib/fputsx.c
lib/getdate.y
lib/getdef.c
lib/gshadow.c
lib/hushed.c
lib/loginprompt.c
lib/obscure.c
lib/port.c
lib/readpassphrase.c
lib/salt.c
lib/setupenv.c
lib/sgetgrent.c
lib/sgetspent.c
lib/shadow.c
lib/sssd.c
lib/tcbfuncs.c
lib/ttytype.c
lib/tz.c
lib/utmp.c
src/chgpasswd.c
src/chpasswd.c
src/groupadd.c
src/login_nopam.c
src/logoutd.c
src/newusers.c
src/passwd.c
src/suauth.c
src/useradd.c
tests/unit/test_chkname.c

index 584e098ac7d0130d89448dd5f8c952423eaf9368..c1c9b9d3d54a671e798d489c2259acf1e177bb98 100644 (file)
@@ -491,12 +491,12 @@ safeget (char *buf, int maxlen)
       bad = (!isalnum (c) && (c != '_') && (c != ' '));
       *(buf++) = c;
     }
-  *buf = '\0';
+  stpcpy(buf, "");
 
   if (bad)
     {
       printf ("\nString contained banned character. Please stick to alphanumerics.\n");
-      *bstart = '\0';
+      stpcpy(bstart, "");
     }
 }
 
index 7bc7067070146127e0993a20340056b5161eb9e9..6a9b7752596a954f3e077a28aa4ddf5b3f75faf9 100644 (file)
@@ -197,7 +197,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
                errno = EINVAL;
                return 0;
        }
-       buf[len] = '\0';
+       stpcpy(&buf[len], "");
        if (get_pid(buf, &pid) == -1) {
                if (log) {
                        (void) fprintf (shadow_logfd,
@@ -659,7 +659,7 @@ int commonio_open (struct commonio_db *db, int mode)
                                goto cleanup_buf;
                        }
                }
-               *strchrnul(buf, '\n') = '\0';
+               stpcpy(strchrnul(buf, '\n'), "");
 
                line = strdup (buf);
                if (NULL == line) {
index fed315c3b1ea007c280658331611abfed4763311..4691fc436cd95034beb2784b5f93718aa48bfae5 100644 (file)
@@ -76,7 +76,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
         */
 
        while (fgets (buf, sizeof (buf), fp) != NULL) {
-               *strchrnul(buf, '\n') = '\0';
+               stpcpy(strchrnul(buf, '\n'), "");
                if (strcmp (buf, tty) == 0) {
                        (void) fclose (fp);
                        return true;
index ae48d10eb54858ade144a28379b9cb51bb2ff4aa..0d855b7166c94f92aa538744959a9c8a1d2baa65 100644 (file)
@@ -17,6 +17,7 @@
 #include <sys/time.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "alloc/malloc.h"
 #include "alloc/x/xmalloc.h"
@@ -563,7 +564,7 @@ static /*@null@*/char *readlink_malloc (const char *filename)
 
                if ((size_t) nchars < size) { /* The buffer was large enough */
                        /* readlink does not nul-terminate */
-                       buffer[nchars] = '\0';
+                       stpcpy(&buffer[nchars], "");
                        return buffer;
                }
 
index b6d2fa14e66b52835a8da53c889412c1d0d5c8a0..256ee34a20dddf408de8eb468cec294e3427c61d 100644 (file)
@@ -84,7 +84,7 @@ void change_field (char *buf, size_t maxsize, const char *prompt)
        if (NULL == cp) {
                return;
        }
-       *cp = '\0';
+       stpcpy(cp, "");
 
        if ('\0' != newf[0]) {
                /*
@@ -92,7 +92,7 @@ void change_field (char *buf, size_t maxsize, const char *prompt)
                 * makes it possible to change the field to empty, by
                 * entering a space.  --marekm
                 */
-               *strrspn(newf, " \t\n") = '\0';
+               stpcpy(strrspn(newf, " \t\n"), "");
 
                cp = newf;
                while (isspace (*cp)) {
index 0565310103361a3fd19c6163799cb42e8002cc1a..72d62099232349c441b09c8c056631a73d6b17c1 100644 (file)
@@ -10,6 +10,8 @@
 #include <config.h>
 
 #include <stdio.h>
+#include <string.h>
+
 #include "defines.h"
 #include "prototypes.h"
 
@@ -33,10 +35,8 @@ fgetsx(/*@returned@*/char *restrict buf, int cnt, FILE *restrict f)
                ep = strrchr (cp, '\\');
                if ((NULL != ep) && (*(ep + 1) == '\n')) {
                        cnt -= ep - cp;
-                       if (cnt > 0) {
-                               cp = ep;
-                               *cp = '\0';
-                       }
+                       if (cnt > 0)
+                               cp = stpcpy(ep, "");
                } else {
                        break;
                }
index b71bf1984a698dd4b35281da545198ad56369209..31f1aa0fbf96a7ad6da2f2e89012b02a9cb6f794 100644 (file)
@@ -646,7 +646,7 @@ static int LookupWord (char *buff)
   else if (strlen (buff) == 4 && buff[3] == '.')
     {
       abbrev = true;
-      buff[3] = '\0';
+      stpcpy(&buff[3], "");
     }
   else
     abbrev = false;
@@ -689,7 +689,7 @@ static int LookupWord (char *buff)
   i = strlen (buff) - 1;
   if (buff[i] == 's')
     {
-      buff[i] = '\0';
+      stpcpy(&buff[i], "");
       for (tp = UnitsTable; tp->name; tp++)
        if (strcmp (buff, tp->name) == 0)
          {
@@ -723,7 +723,7 @@ static int LookupWord (char *buff)
       *p++ = *q;
     else
       i++;
-  *p = '\0';
+  stpcpy(p, "");
   if (0 != i)
     for (tp = TimezoneTable; NULL != tp->name; tp++)
       if (strcmp (buff, tp->name) == 0)
@@ -772,7 +772,7 @@ yylex (void)
          for (p = buff; (c = *yyInput++, isalpha (c)) || c == '.';)
            if (p < &buff[sizeof buff - 1])
              *p++ = c;
-         *p = '\0';
+          stpcpy(p, "");
          yyInput--;
          return LookupWord (buff);
        }
index 91f40702f09117c305c6d1a586a86315ea1a81a1..d33f45b14e29c75ee97a9704a2e4d01898357605 100644 (file)
@@ -560,7 +560,7 @@ static void def_load (void)
                /*
                 * Trim trailing whitespace.
                 */
-               *strrspn(buf, " \t\n") = '\0';
+               stpcpy(strrspn(buf, " \t\n"), "");
 
                /*
                 * Break the line into two fields.
@@ -573,9 +573,9 @@ static void def_load (void)
                if (*s == '\0')
                        continue;       /* only 1 field?? */
 
-               *s++ = '\0';
+               stpcpy(s++, "");
                value = stpspn(s, " \"\t");     /* next nonwhite */
-               *strchrnul(value, '"') = '\0';
+               stpcpy(strchrnul(value, '"'), "");
 
                /*
                 * Store the value in def_table.
index 042138882acfcab259f1fd02731b32d68e8255a6..e79fb784119e30471f7297986d5a1b232cf55601 100644 (file)
@@ -91,7 +91,7 @@ void endsgent (void)
        }
 
        strcpy (sgrbuf, string);
-       *strchrnul(sgrbuf, '\n') = '\0';
+       stpcpy(strchrnul(sgrbuf, '\n'), "");
 
        /*
         * There should be exactly 4 colon separated fields.  Find
@@ -172,7 +172,7 @@ void endsgent (void)
                                return NULL;
                        }
                }
-               *strchrnul(buf, '\n') = '\0';
+               stpcpy(strchrnul(buf, '\n'), "");
                return (sgetsgent (buf));
        }
        return NULL;
@@ -244,53 +244,36 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
        /*
         * Copy the group name and passwd.
         */
-
-       strcpy (cp, sgrp->sg_name);
-       cp += strlen (cp);
-       *cp++ = ':';
-
-       strcpy (cp, sgrp->sg_passwd);
-       cp += strlen (cp);
-       *cp++ = ':';
+       cp = stpcpy(stpcpy(cp, sgrp->sg_name), ":");
+       cp = stpcpy(stpcpy(cp, sgrp->sg_passwd), ":");
 
        /*
         * Copy the administrators, separating each from the other
         * with a ",".
         */
-
        for (i = 0; NULL != sgrp->sg_adm[i]; i++) {
-               if (i > 0) {
-                       *cp++ = ',';
-               }
+               if (i > 0)
+                       cp = stpcpy(cp, ",");
 
-               strcpy (cp, sgrp->sg_adm[i]);
-               cp += strlen (cp);
+               cp = stpcpy(cp, sgrp->sg_adm[i]);
        }
-       *cp = ':';
-       cp++;
+       cp = stpcpy(cp, ":");
 
        /*
         * Now do likewise with the group members.
         */
-
        for (i = 0; NULL != sgrp->sg_mem[i]; i++) {
-               if (i > 0) {
-                       *cp = ',';
-                       cp++;
-               }
+               if (i > 0)
+                       cp = stpcpy(cp, ",");
 
-               strcpy (cp, sgrp->sg_mem[i]);
-               cp += strlen (cp);
+               cp = stpcpy(cp, sgrp->sg_mem[i]);
        }
-       *cp = '\n';
-       cp++;
-       *cp = '\0';
+       stpcpy(cp, "\n");
 
        /*
         * Output using the function which understands the line
         * continuation conventions.
         */
-
        if (fputsx (buf, fp) == EOF) {
                free (buf);
                return -1;
index a0fc38f1b9d178c1de6da697427709cde420fa39..3db09abb1a2ba27b4f334ec2570c525bbb471fda 100644 (file)
@@ -72,7 +72,7 @@ bool hushed (const char *username)
                return false;
        }
        for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) {
-               *strchrnul(buf, '\n') = '\0';
+               stpcpy(strchrnul(buf, '\n'), "");
                found = (strcmp (buf, pw->pw_shell) == 0) ||
                        (strcmp (buf, pw->pw_name) == 0);
        }
index 7c753180340bfae94235937bfc2814c5bf9cd59d..6233625acce38db6b0696bf170c7c580e670fea8 100644 (file)
@@ -87,7 +87,7 @@ void login_prompt (char *name, int namesize)
        if (NULL == cp) {
                exit (EXIT_FAILURE);
        }
-       *cp = '\0';             /* remove \n [ must be there ] */
+       stpcpy(cp, "");         /* remove \n [ must be there ] */
 
        /*
         * Skip leading whitespace.  This makes "  username" work right.
@@ -98,7 +98,7 @@ void login_prompt (char *name, int namesize)
 
        for (i = 0; i < namesize - 1 && *cp != '\0'; name[i++] = *cp++);
 
-       name[i] = '\0';
+       stpcpy(&name[i], "");
 
        /*
         * Set the SIGQUIT handler back to its original value
index 136f26a67302583605c966fd29a287265f9b8511..74a32f0c3db3b301c7b0e909385a4326b23d6354 100644 (file)
@@ -189,12 +189,10 @@ static /*@observer@*//*@null@*/const char *obscure_msg (
 
        new1 = xstrdup (new);
        old1 = xstrdup (old);
-       if (newlen > maxlen) {
-               new1[maxlen] = '\0';
-       }
-       if (oldlen > maxlen) {
-               old1[maxlen] = '\0';
-       }
+       if (newlen > maxlen)
+               stpcpy(&new1[maxlen], "");
+       if (oldlen > maxlen)
+               stpcpy(&old1[maxlen], "");
 
        msg = password_check (old1, new1, pwdp);
 
index d70957d97deb701d454d3d60e453f85db289f282..03543d5d6a76e77351f74a0a0eba9ea73856ad84 100644 (file)
@@ -152,7 +152,7 @@ again:
         * TTY devices.
         */
 
-       *strchrnul(buf, '\n') = '\0';
+       stpcpy(strchrnul(buf, '\n'), "");
 
        port.pt_names = ttys;
        for (cp = buf, j = 0; j < PORT_TTY; j++) {
@@ -165,12 +165,10 @@ again:
                        break;
                }
 
-               if (',' == *cp) {       /* end of current tty name */
-                       *cp++ = '\0';
-               }
+               if (',' == *cp)         /* end of current tty name */
+                       stpcpy(cp++, "");
        }
-       *cp = '\0';
-       cp++;
+       stpcpy(cp++, "");
        port.pt_names[j] = NULL;
 
        /*
@@ -186,8 +184,7 @@ again:
 
                for (j = 1; ':' != *cp; cp++) {
                        if ((',' == *cp) && (j < PORT_IDS)) {
-                               *cp = '\0';
-                               cp++;
+                               stpcpy(cp++, "");
                                port.pt_users[j] = cp;
                                j++;
                        }
@@ -201,8 +198,7 @@ again:
                goto again;
        }
 
-       *cp = '\0';
-       cp++;
+       stpcpy(cp++, "");
 
        /*
         * Get the list of valid times.  The times field is the third
index 5ff060cca780973b6ff18c8344faff8843944d1b..e23960f0126b82a35ac603d2379e4fe56ee7c2f1 100644 (file)
@@ -141,7 +141,7 @@ restart:
                        *p++ = ch;
                }
        }
-       *p = '\0';
+       stpcpy(p, "");
        save_errno = errno;
        if (!(term.c_lflag & ECHO))
                (void)write(output, "\n", 1);
index 529d59cace4d087ad51568ab1bfa68d893a33811..efef4e59ca4f123600a8bddc65cecdaf34754c95 100644 (file)
@@ -291,6 +291,7 @@ static /*@observer@*/unsigned long YESCRYPT_get_salt_cost (/*@null@*/const int *
 static /*@observer@*/void YESCRYPT_salt_cost_to_buf (char *buf, unsigned long cost)
 {
        const size_t buf_begin = strlen (buf);
+       char  *p;
 
        /*
         * Check if the result buffer is long enough.
@@ -302,17 +303,17 @@ static /*@observer@*/void YESCRYPT_salt_cost_to_buf (char *buf, unsigned long co
         */
        assert (GENSALT_SETTING_SIZE > buf_begin + 4);
 
-       buf[buf_begin + 0] = 'j';
+       p = &buf[buf_begin];
+       p = stpcpy(p, "j");
        if (cost < 3) {
-               buf[buf_begin + 1] = 0x36 + cost;
+               *p++ = 0x36 + cost;
        } else if (cost < 6) {
-               buf[buf_begin + 1] = 0x34 + cost;
+               *p++ = 0x34 + cost;
        } else {
-               buf[buf_begin + 1] = 0x3b + cost;
+               *p++ = 0x3b + cost;
        }
-       buf[buf_begin + 2] = cost >= 3 ? 'T' : '5';
-       buf[buf_begin + 3] = '$';
-       buf[buf_begin + 4] = '\0';
+       p = stpcpy(p, (cost >= 3) ? "T" : "5");
+       stpcpy(p, "$");
 }
 #endif /* USE_YESCRYPT */
 
@@ -330,7 +331,7 @@ static /*@observer@*/const char *gensalt (size_t salt_size)
                strcat (salt, l64a (csrand ()));
        } while (strlen (salt) < salt_size);
 
-       salt[salt_size] = '\0';
+       stpcpy(&salt[salt_size], "");
 
        return salt;
 }
@@ -421,7 +422,7 @@ static /*@observer@*/const char *gensalt (size_t salt_size)
                salt_len = GENSALT_SETTING_SIZE - 1;
                rounds = 0;
                memset(result, '.', salt_len);
-               result[salt_len] = '\0';
+               stpcpy(&result[salt_len], "");
        }
 
        char *retval = crypt_gensalt (result, rounds, NULL, 0);
index 8eda5d58f3be45dc39104c74e72ed6e89f98422d..6ed08c98ce43ca6a06ced96d551200b5ca94a533 100644 (file)
@@ -56,7 +56,7 @@ static void read_env_file (const char *filename)
                if (NULL == cp) {
                        break;
                }
-               *cp = '\0';
+               stpcpy(cp, "");
 
                cp = buf;
                /* ignore whitespace and comments */
@@ -78,8 +78,7 @@ static void read_env_file (const char *filename)
                        continue;
                }
                /* NUL-terminate the name */
-               *cp = '\0';
-               cp++;
+               stpcpy(cp++, "");
                val = cp;
 #if 0                          /* XXX untested, and needs rewrite with fewer goto's :-) */
 /*
@@ -112,7 +111,7 @@ static void read_env_file (const char *filename)
                        goto finished;
                } else if (isspace (*cp)) {
                        /* unescaped whitespace - end of string */
-                       *cp = '\0';
+                       stpcpy(cp, "");
                        goto finished;
                } else {
                        cp++;
index f62f6973cba482526fff222e5e3133810eb21bd5..36137bcf59afc3e9f127e31f364998c2e49325bd 100644 (file)
@@ -83,7 +83,7 @@ struct group *sgetgrent (const char *buf)
                }
        }
        strcpy (grpbuf, buf);
-       *strchrnul(grpbuf, '\n') = '\0';
+       stpcpy(strchrnul(grpbuf, '\n'), "");
 
        for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
                grpfields[i] = strsep(&cp, ":");
index f4ace5218bb6feff999a50252b52f55d89302493..c693acd08799570972041305accc3a281ea4be56 100644 (file)
@@ -54,7 +54,7 @@ sgetspent(const char *string)
                return NULL;    /* fail if too long */
        }
        strcpy (spwbuf, string);
-       *strchrnul(spwbuf, '\n') = '\0';
+       stpcpy(strchrnul(spwbuf, '\n'), "");
 
        /*
         * Tokenize the string into colon separated fields.  Allow up to
index 3a867ae2785f65f31dac12ff23087d257dd2a5d0..3152595c0580844197fccb077062d23086f74f2f 100644 (file)
@@ -77,7 +77,7 @@ static struct spwd *my_sgetspent (const char *string)
        if (strlen (string) >= sizeof spwbuf)
                return 0;
        strcpy (spwbuf, string);
-       *strchrnul(spwbuf, '\n') = '\0';
+       stpcpy(strchrnul(spwbuf, '\n'), "");
 
        /*
         * Tokenize the string into colon separated fields.  Allow up to
@@ -202,7 +202,7 @@ struct spwd *fgetspent (FILE * fp)
 
        if (fgets (buf, sizeof buf, fp) != NULL)
        {
-               *strchrnul(buf, '\n') = '\0';
+               stpcpy(strchrnul(buf, '\n'), "");
                return my_sgetspent (buf);
        }
        return 0;
index 4db799543bd640dfec65af091e84830ca95e80c4..09f539f46ca9020e029f98ff095b775526b3e35d 100644 (file)
@@ -24,7 +24,7 @@ int
 sssd_flush_cache(int dbflags)
 {
        int          status, code, rv;
-       int          i = 0;
+       char         *p;
        char         *sss_cache_args = NULL;
        const char   *cmd = "/usr/sbin/sss_cache";
        const char   *spawnedArgs[] = {"sss_cache", NULL, NULL};
@@ -40,15 +40,13 @@ sssd_flush_cache(int dbflags)
            return -1;
        }
 
-       sss_cache_args[i++] = '-';
-       if (dbflags & SSSD_DB_PASSWD) {
-               sss_cache_args[i++] = 'U';
-       }
-       if (dbflags & SSSD_DB_GROUP) {
-               sss_cache_args[i++] = 'G';
-       }
-       sss_cache_args[i++] = '\0';
-       if (i == 2) {
+       p = stpcpy(sss_cache_args, "-");
+       if (dbflags & SSSD_DB_PASSWD)
+               stpcpy(p, "U");
+       if (dbflags & SSSD_DB_GROUP)
+               stpcpy(p, "G");
+
+       if (*p == '\0') {
                /* Neither passwd nor group, nothing to do */
                free(sss_cache_args);
                return 0;
index b5915fcd23a111f6fe197ce842cc4e93457a7329..3dc2abd700e8e6db1a8cd6481178e015b8c8c328 100644 (file)
@@ -135,13 +135,13 @@ static /*@null@*/ char *shadowtcb_path_rel_existing (const char *name)
        }
        free (path);
        if ((size_t)ret >= sizeof(link) - 1) {
-               link[sizeof(link) - 1] = '\0';
+               stpcpy(&link[sizeof(link) - 1], "");
                fprintf (shadow_logfd,
                         _("%s: Suspiciously long symlink: %s\n"),
                         shadow_progname, link);
                return NULL;
        }
-       link[ret] = '\0';
+       stpcpy(&link[ret], "");
        rval = strdup (link);
        if (NULL == rval) {
                OUT_OF_MEMORY;
@@ -200,7 +200,7 @@ static shadowtcb_status mkdir_leading (const char *name, uid_t uid)
                goto out_free_path;
        }
        while ((ind = strchr (ptr, '/'))) {
-               *ind = '\0';
+               stpcpy(ind, "");
                if (asprintf (&dir, TCB_DIR "/%s", path) == -1) {
                        OUT_OF_MEMORY;
                        return SHADOWTCB_FAILURE;
@@ -266,7 +266,7 @@ static shadowtcb_status rmdir_leading (char *path)
        char *ind, *dir;
        shadowtcb_status ret = SHADOWTCB_SUCCESS;
        while ((ind = strrchr (path, '/'))) {
-               *ind = '\0';
+               stpcpy(ind, "");
                if (asprintf (&dir, TCB_DIR "/%s", path) == -1) {
                        OUT_OF_MEMORY;
                        return SHADOWTCB_FAILURE;
index b07b686245e03c42e955f6e8ecae73a41962431a..c0f6de6fed57f7dc1d4186175d42c44b47db20cb 100644 (file)
@@ -49,7 +49,7 @@ void ttytype (const char *line)
                        continue;
                }
 
-               *strchrnul(buf, '\n') = '\0';
+               stpcpy(strchrnul(buf, '\n'), "");
 
                if (   (sscanf (buf, "%1023s %1023s", type, port) == 2)
                    && (strcmp (line, port) == 0)) {
index c22268bf62e0efe32ab349c42de43f45dbf0520f..cb04e517310612c97de513da315a114630c18d3f 100644 (file)
--- a/lib/tz.c
+++ b/lib/tz.c
@@ -42,7 +42,7 @@
 
                strcpy (tzbuf, def_tz);
        } else {
-               *strchrnul(tzbuf, '\n') = '\0';
+               stpcpy(strchrnul(tzbuf, '\n'), "");
        }
 
        if (NULL != fp) {
index e8f9c793767a7c6700ce5b832aa4da704a567cc2..4e10eb9864ec9ccd6fd274f4d0d340b2bb4c3172 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <stdio.h>
+#include <string.h>
 #include <fcntl.h>
 
 #include "alloc/x/xcalloc.h"
@@ -46,7 +47,7 @@ is_my_tty(const char tty[UTX_LINESIZE])
        /* tmptty shall be bigger than full_tty */
        static char  tmptty[sizeof(full_tty) + 1];
 
-       full_tty[0] = '\0';
+       stpcpy(full_tty, "");
        if (tty[0] != '/')
                strcpy (full_tty, "/dev/");
        strncat(full_tty, tty, UTX_LINESIZE);
index 1ff6776b1295ca5624d6e8e2e797862ee8c52ff1..6c1e632dce77eb7e8445124d7a4bdad1b185d2fc 100644 (file)
@@ -462,7 +462,7 @@ int main (int argc, char **argv)
                line++;
                cp = strrchr (buf, '\n');
                if (NULL != cp) {
-                       *cp = '\0';
+                       stpcpy(cp, "");
                } else {
                        fprintf (stderr, _("%s: line %d: line too long\n"),
                                 Prog, line);
@@ -482,7 +482,7 @@ int main (int argc, char **argv)
                name = buf;
                cp = strchr (name, ':');
                if (NULL != cp) {
-                       *cp = '\0';
+                       stpcpy(cp, "");
                        cp++;
                } else {
                        fprintf (stderr,
index 79880f568e9febce823b373ab4cd0548fb1c0a8b..5d87119aac61f81ede94809ad78794b5e774804d 100644 (file)
@@ -503,7 +503,7 @@ int main (int argc, char **argv)
                line++;
                cp = strrchr (buf, '\n');
                if (NULL != cp) {
-                       *cp = '\0';
+                       stpcpy(cp, "");
                } else {
                        if (feof (stdin) == 0) {
 
@@ -535,8 +535,7 @@ int main (int argc, char **argv)
                name = buf;
                cp = strchr (name, ':');
                if (NULL != cp) {
-                       *cp = '\0';
-                       cp++;
+                       stpcpy(cp++, "");
                } else {
                        fprintf (stderr,
                                 _("%s: line %d: missing new password\n"),
index 095a41eedd61975c4e446f14c590a4368acf4afc..f83bd1f574f6bf3e1c749b496bb854bd08b5f457 100644 (file)
@@ -431,7 +431,7 @@ static void process_flags (int argc, char **argv)
                                exit (E_BAD_ARG);
                        }
                        /* terminate name, point to value */
-                       *cp++ = '\0';
+                       stpcpy(cp++, "");
                        if (putdef_str (optarg, cp, NULL) < 0) {
                                exit (E_BAD_ARG);
                        }
index 03a2871f4d40f28735e38fae5385e72aba7ee2b7..b9fb647c0b4648646fdfca5252f161d4cc6c6b28 100644 (file)
@@ -111,7 +111,7 @@ int login_access (const char *user, const char *from)
                        if (line[0] == '#') {
                                continue;       /* comment line */
                        }
-                       *strrspn(line, " \t\n") = '\0';
+                       stpcpy(strrspn(line, " \t\n"), "");
                        if (line[0] == '\0') {  /* skip blank lines */
                                continue;
                        }
@@ -182,7 +182,7 @@ static char *myhostname (void)
 
        if (name[0] == '\0') {
                gethostname (name, sizeof (name));
-               name[MAXHOSTNAMELEN] = '\0';
+               stpcpy(&name[MAXHOSTNAMELEN], "");
        }
        return (name);
 }
@@ -222,7 +222,7 @@ static bool user_match (const char *tok, const char *string)
         */
        at = strchr (tok + 1, '@');
        if (NULL != at) {       /* split user@host pattern */
-               *at = '\0';
+               stpcpy(at, "");
                return (   user_match (tok, string)
                        && from_match (at + 1, myhostname ()));
 #if HAVE_INNETGR
index d77f757fb3066b6133b344e6953b708a01e8fb74..11a5d60a3b6b25c28ec64a818f2aed5c05fb82aa 100644 (file)
@@ -200,11 +200,10 @@ main(int argc, char **argv)
                        }
                        /* child */
 
-                       if (strncmp (ut->ut_line, "/dev/", 5) != 0) {
-                               strcpy (tty_name, "/dev/");
-                       } else {
-                               tty_name[0] = '\0';
-                       }
+                       if (strncmp(ut->ut_line, "/dev/", 5) != 0)
+                               strcpy(tty_name, "/dev/");
+                       else
+                               strcpy(tty_name, "");
 
                        STRNCAT(tty_name, ut->ut_line);
 #ifndef O_NOCTTY
index 4f7b96fa87b96630d8b47a6a19a1c76e6c1a0f08..6a87e3d9cfffccd6cde118ec5a3a08626e101b04 100644 (file)
@@ -1107,9 +1107,8 @@ int main (int argc, char **argv)
                                 Prog, line);
                        fail_exit (EXIT_FAILURE);
                }
-               if (cp != NULL) {
-                       *cp = '\0';
-               }
+               if (cp != NULL)
+                       stpcpy(cp, "");
 
                /*
                 * Break the string into fields and screw around with them.
index f1fc6595fd195148a77d4ddbf527d54d499dbf88..b7bf925db479d4ef86dc143694e1aa469c486d9b 100644 (file)
@@ -226,7 +226,7 @@ static int new_password (const struct passwd *pw)
                erase_pass (clear);
                strzero (cipher);
        } else {
-               orig[0] = '\0';
+               strcpy(orig, "");
        }
 
        /*
@@ -514,9 +514,8 @@ static char *update_crypt_pw (char *cp)
                }
        }
 
-       if (dflg) {
-               *cp = '\0';
-       }
+       if (dflg)
+               strcpy(cp, "");
 
        if (uflg && *cp == '!') {
                if (cp[1] == '\0') {
index ed45a8564241255858c72fb43993c67e31eafd50..ac9af264f539d720d9d601db9e8f39270996ef6a 100644 (file)
@@ -81,7 +81,7 @@ int check_su_auth (const char *actual_id,
                        continue;
                }
 
-               *strrspn(temp, " \t\n") = '\0';
+               stpcpy(strrspn(temp, " \t\n"), "");
 
                posn = 0;
                while (temp[posn] == ' ' || temp[posn] == '\t')
index d307aecae9366382762f55c86fd1d222dbfaf647..bb907bab67c85ac18c1dd0c57b8377e988510a65 100644 (file)
@@ -361,7 +361,7 @@ static void get_defaults (void)
         * values are used, everything else can be ignored.
         */
        while (fgets (buf, sizeof buf, fp) == buf) {
-               *strchrnul(buf, '\n') = '\0';
+               stpcpy(strchrnul(buf, '\n'), "");
 
                cp = strchr (buf, '=');
                if (NULL == cp) {
@@ -605,7 +605,7 @@ static int set_defaults (void)
        while (fgets (buf, sizeof buf, ifp) == buf) {
                cp = strrchr (buf, '\n');
                if (NULL != cp) {
-                       *cp = '\0';
+                       stpcpy(cp, "");
                } else {
                        /* A line which does not end with \n is only valid
                         * at the end of the file.
@@ -1358,8 +1358,7 @@ static void process_flags (int argc, char **argv)
                                        exit (E_BAD_ARG);
                                }
                                /* terminate name, point to value */
-                               *cp = '\0';
-                               cp++;
+                               stpcpy(cp++, "");
                                if (putdef_str (optarg, cp, NULL) < 0) {
                                        exit (E_BAD_ARG);
                                }
@@ -2223,7 +2222,7 @@ static void create_home (void)
        if (access (prefix_user_home, F_OK) == 0)
                return;
 
-       path[0] = '\0';
+       strcpy(path, "");
        bhome = strdup(prefix_user_home);
        if (!bhome) {
                fprintf(stderr,
@@ -2269,7 +2268,7 @@ static void create_home (void)
                                        Prog, path);
                                fail_exit(E_HOMEDIR);
                        }
-                       btrfs_check[strlen(path) - strlen(cp) - 1] = '\0';
+                       stpcpy(&btrfs_check[strlen(path) - strlen(cp) - 1], "");
                        if (is_btrfs(btrfs_check) <= 0) {
                                fprintf(stderr,
                                        _("%s: home directory \"%s\" must be mounted on BTRFS\n"),
index 127114dcbc87197cc9553ee139ddc1a7034ee985..3f190a773ef9d42d5f86a681bbeb9e0611844f70 100644 (file)
@@ -139,10 +139,10 @@ test_is_valid_user_name_long(void **state)
 
        memset(name, '_', max);
 
-       name[max] = '\0';
+       stpcpy(&name[max], "");
        assert_true(false == is_valid_user_name(name));
 
-       name[max - 1] = '\0';
+       stpcpy(&name[max - 1], "");
        assert_true(is_valid_user_name(name));
 
        free(name);