From d8cb4ccdf71232e15b37d532085e36a9ddd22f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Sun, 6 Jun 2004 21:58:51 +0000 Subject: [PATCH] Cleaned. Replaced multiple strcpy/cat by g_strdup_printf. Replaced strncpy * gnuslib.c: (connect_to_internet_server): Cleaned. * mountlist.c: (glibtop_get_mountlist_s): Replaced multiple strcpy/cat by g_strdup_printf. Replaced strncpy by g_strlcpy. --- sysdeps/common/ChangeLog | 6 ++++++ sysdeps/common/gnuslib.c | 2 +- sysdeps/common/mountlist.c | 24 ++++++++---------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/sysdeps/common/ChangeLog b/sysdeps/common/ChangeLog index 1f413790..5a04f4ad 100644 --- a/sysdeps/common/ChangeLog +++ b/sysdeps/common/ChangeLog @@ -1,3 +1,9 @@ +2004-06-06 BenoƮt Dejean + + * gnuslib.c: (connect_to_internet_server): Cleaned. + * mountlist.c: (glibtop_get_mountlist_s): Replaced multiple strcpy/cat by + g_strdup_printf. Replaced strncpy by g_strlcpy. + 2004-03-15 Bastien Nocera * fsusage.c: diff --git a/sysdeps/common/gnuslib.c b/sysdeps/common/gnuslib.c index 67abf508..b486569c 100644 --- a/sysdeps/common/gnuslib.c +++ b/sysdeps/common/gnuslib.c @@ -241,7 +241,7 @@ connect_to_internet_server (const char *serverhost, u_short port) char buf[512]; /* temporary buffer */ /* clear out address structures */ - memset ((char *) &peeraddr_in, 0, sizeof (struct sockaddr_in)); + memset (&peeraddr_in, 0, sizeof (struct sockaddr_in)); /* Set up the peer address to which we will connect. */ peeraddr_in.sin_family = AF_INET; diff --git a/sysdeps/common/mountlist.c b/sysdeps/common/mountlist.c index d35914a7..9152c054 100644 --- a/sysdeps/common/mountlist.c +++ b/sysdeps/common/mountlist.c @@ -439,9 +439,7 @@ read_filesystem_list (need_fs_type, all_fs) #ifdef GETFSTYP /* SVR3. */ me->me_devname = g_strdup (mnt.mt_dev); #else - me->me_devname = g_malloc (strlen (mnt.mt_dev) + 6); - strcpy (me->me_devname, "/dev/"); - strcpy (me->me_devname + 5, mnt.mt_dev); + me->me_devname = g_strdup_printf("/dev/%s", mnt.mt_dev); #endif me->me_mountdir = g_strdup (mnt.mt_filsys); me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ @@ -546,10 +544,7 @@ read_filesystem_list (need_fs_type, all_fs) /* Prepend the remote pathname. */ host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; - me->me_devname = g_malloc (strlen (host) + strlen (path) + 2); - strcpy (me->me_devname, host); - strcat (me->me_devname, ":"); - strcat (me->me_devname, path); + me->me_devname = g_strdup_printf("%s:%s", host, path); } else { @@ -606,24 +601,21 @@ glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs) mount_list = g_malloc (buf->total); - /* Write data into mount_list. */ + /* Write data into mount_list and free memory. */ - for (count = 0, tmp = me; tmp; count++, tmp = tmp->me_next) { - strncpy (mount_list [count].devname, tmp->me_devname, + for (count = 0, tmp = me; tmp; count++, tmp = next) { + + g_strlcpy (mount_list [count].devname, tmp->me_devname, GLIBTOP_MOUNTENTRY_LEN); - strncpy (mount_list [count].mountdir, tmp->me_mountdir, + g_strlcpy (mount_list [count].mountdir, tmp->me_mountdir, GLIBTOP_MOUNTENTRY_LEN); - strncpy (mount_list [count].type, tmp->me_type, + g_strlcpy (mount_list [count].type, tmp->me_type, GLIBTOP_MOUNTENTRY_LEN); mount_list [count].devname [GLIBTOP_MOUNTENTRY_LEN] = 0; mount_list [count].mountdir [GLIBTOP_MOUNTENTRY_LEN] = 0; mount_list [count].type [GLIBTOP_MOUNTENTRY_LEN] = 0; mount_list [count].dev = tmp->me_dev; - } - /* Free memory. */ - - for (count = 0, tmp = me; tmp; count++, tmp = next) { next = tmp->me_next; g_free (tmp->me_devname); g_free (tmp->me_mountdir);