summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2012-07-15 11:38:51 +0200
committerJim Meyering <meyering@redhat.com>2012-07-15 13:43:49 +0200
commitf79263da4da048bf3a071e22530a0d2c02aff0df (patch)
treeeb67b1c28b4272d4e3c8a9c43dd5c0b31d734ea6 /src
parent3c2973b86e70f184e95c4c87086095f52c2bb493 (diff)
downloadcoreutils-f79263da4da048bf3a071e22530a0d2c02aff0df.tar.xz
maint: remove unwarranted uses of strncpy
* src/pinky.c (print_entry): Remove unwarranted uses of strncpy. Instead, use stpcpy and stpncpy. * src/who.c (print_user): Likewise. * cfg.mk: Remove strncpy exemptions.
Diffstat (limited to 'src')
-rw-r--r--src/pinky.c21
-rw-r--r--src/who.c19
2 files changed, 11 insertions, 29 deletions
diff --git a/src/pinky.c b/src/pinky.c
index 597bc56c0..c01b12427 100644
--- a/src/pinky.c
+++ b/src/pinky.c
@@ -208,21 +208,14 @@ print_entry (const STRUCT_UTMP *utmp_ent)
#define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1)
char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1];
+ char *p = line;
/* Copy ut_line into LINE, prepending '/dev/' if ut_line is not
already an absolute file name. Some system may put the full,
absolute file name in ut_line. */
- if (utmp_ent->ut_line[0] == '/')
- {
- strncpy (line, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
- line[sizeof (utmp_ent->ut_line)] = '\0';
- }
- else
- {
- strcpy (line, DEV_DIR_WITH_TRAILING_SLASH);
- strncpy (line + DEV_DIR_LEN, utmp_ent->ut_line, sizeof utmp_ent->ut_line);
- line[DEV_DIR_LEN + sizeof (utmp_ent->ut_line)] = '\0';
- }
+ if ( ! IS_ABSOLUTE_FILE_NAME (utmp_ent->ut_line))
+ p = stpcpy (p, DEV_DIR_WITH_TRAILING_SLASH);
+ stpncpy (p, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
if (stat (line, &stats) == 0)
{
@@ -242,8 +235,7 @@ print_entry (const STRUCT_UTMP *utmp_ent)
struct passwd *pw;
char name[UT_USER_SIZE + 1];
- strncpy (name, UT_USER (utmp_ent), UT_USER_SIZE);
- name[UT_USER_SIZE] = '\0';
+ stpncpy (name, UT_USER (utmp_ent), UT_USER_SIZE);
pw = getpwnam (name);
if (pw == NULL)
/* TRANSLATORS: Real name is unknown; at most 19 characters. */
@@ -284,8 +276,7 @@ print_entry (const STRUCT_UTMP *utmp_ent)
char *display = NULL;
/* Copy the host name into UT_HOST, and ensure it's nul terminated. */
- strncpy (ut_host, utmp_ent->ut_host, (int) sizeof (utmp_ent->ut_host));
- ut_host[sizeof (utmp_ent->ut_host)] = '\0';
+ stpncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
/* Look for an X display. */
display = strchr (ut_host, ':');
diff --git a/src/who.c b/src/who.c
index c875b1de6..3ad800429 100644
--- a/src/who.c
+++ b/src/who.c
@@ -342,23 +342,15 @@ print_user (const STRUCT_UTMP *utmp_ent, time_t boottime)
#define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1)
char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1];
+ char *p = line;
PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
/* Copy ut_line into LINE, prepending '/dev/' if ut_line is not
already an absolute file name. Some systems may put the full,
absolute file name in ut_line. */
- if (utmp_ent->ut_line[0] == '/')
- {
- strncpy (line, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
- line[sizeof (utmp_ent->ut_line)] = '\0';
- }
- else
- {
- strcpy (line, DEV_DIR_WITH_TRAILING_SLASH);
- strncpy (line + DEV_DIR_LEN, utmp_ent->ut_line,
- sizeof (utmp_ent->ut_line));
- line[DEV_DIR_LEN + sizeof (utmp_ent->ut_line)] = '\0';
- }
+ if ( ! IS_ABSOLUTE_FILE_NAME (utmp_ent->ut_line))
+ p = stpcpy (p, DEV_DIR_WITH_TRAILING_SLASH);
+ stpncpy (p, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
if (stat (line, &stats) == 0)
{
@@ -384,8 +376,7 @@ print_user (const STRUCT_UTMP *utmp_ent, time_t boottime)
char *display = NULL;
/* Copy the host name into UT_HOST, and ensure it's nul terminated. */
- strncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
- ut_host[sizeof (utmp_ent->ut_host)] = '\0';
+ stpncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
/* Look for an X display. */
display = strchr (ut_host, ':');