diff options
author | Benoît Dejean <bdejean@src.gnome.org> | 2004-06-06 22:07:44 +0000 |
---|---|---|
committer | Benoît Dejean <bdejean@src.gnome.org> | 2004-06-06 22:07:44 +0000 |
commit | 54fb1482ba60b53140f45c3a7937b3b7a5738d86 (patch) | |
tree | d5b4a813ab37e636fc5cf9065d02f5709593ce7d | |
parent | 2f87aa447956208a35a35300d56f4100bf028529 (diff) | |
download | libgtop-54fb1482ba60b53140f45c3a7937b3b7a5738d86.tar.gz |
Removed. Cleaned. Replaced unsafe strcpy by g_strlcpy.
* glibtop_machine.h (skip_token): Removed.
* glibtop_server.h (skip_multiple_token): Cleaned.
* netload.c: (glibtop_get_netload_s): Replaced unsafe strcpy by g_strlcpy.
* procmap.c: (glibtop_get_proc_map_s): s/strncpy/g_strlcpy/.
* procstate.c: (glibtop_get_proc_state_s): Likewise.
* sysinfo.c: (init_sysinfo): Cleaned.
-rw-r--r-- | sysdeps/linux/ChangeLog | 9 | ||||
-rw-r--r-- | sysdeps/linux/glibtop_machine.h | 12 | ||||
-rw-r--r-- | sysdeps/linux/glibtop_server.h | 4 | ||||
-rw-r--r-- | sysdeps/linux/netload.c | 8 | ||||
-rw-r--r-- | sysdeps/linux/procmap.c | 5 | ||||
-rw-r--r-- | sysdeps/linux/procstate.c | 3 | ||||
-rw-r--r-- | sysdeps/linux/sysinfo.c | 9 |
7 files changed, 23 insertions, 27 deletions
diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index d85eebfc..2e856fed 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,3 +1,12 @@ +2004-06-07 Benoît Dejean <tazforever@dlfp.org> + + * glibtop_machine.h (skip_token): Removed. + * glibtop_server.h (skip_multiple_token): Cleaned. + * netload.c: (glibtop_get_netload_s): Replaced unsafe strcpy by g_strlcpy. + * procmap.c: (glibtop_get_proc_map_s): s/strncpy/g_strlcpy/. + * procstate.c: (glibtop_get_proc_state_s): Likewise. + * sysinfo.c: (init_sysinfo): Cleaned. + 2004-05-26 Benoît Dejean <tazforever@dlfp.org> * cpu.c: (glibtop_get_cpu_s): Cleaned whitespaces. diff --git a/sysdeps/linux/glibtop_machine.h b/sysdeps/linux/glibtop_machine.h index fb8e34c2..95f1f214 100644 --- a/sysdeps/linux/glibtop_machine.h +++ b/sysdeps/linux/glibtop_machine.h @@ -30,18 +30,6 @@ G_BEGIN_DECLS -#if _IN_LIBGTOP - -static inline char * -skip_token(const char *p) -{ - while (isspace(*p)) p++; - while (*p && !isspace(*p)) p++; - return (char *)p; -} - -#endif - typedef struct _glibtop_machine glibtop_machine; struct _glibtop_machine diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h index e40c6bc6..b8bcbb49 100644 --- a/sysdeps/linux/glibtop_server.h +++ b/sysdeps/linux/glibtop_server.h @@ -42,9 +42,9 @@ skip_token (const char *p) } static inline char * -skip_multiple_token (const char *p, int count) +skip_multiple_token (const char *p, size_t count) { - int i; + size_t i; for (i = 0; i < count; i++) p = skip_token (p); diff --git a/sysdeps/linux/netload.c b/sysdeps/linux/netload.c index f73c8b90..c22989ff 100644 --- a/sysdeps/linux/netload.c +++ b/sysdeps/linux/netload.c @@ -114,7 +114,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, struct ifreq ifr; unsigned long long flags; - strcpy (ifr.ifr_name, interface); + g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name); if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) { buf->flags |= (1L << GLIBTOP_NETLOAD_IF_FLAGS); flags = ifr.ifr_flags; @@ -151,7 +151,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, if (flags & IFF_MULTICAST) buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST); - strcpy (ifr.ifr_name, interface); + g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name); if (!ioctl (skfd, SIOCGIFADDR, &ifr)) { struct sockaddr_in addr = *(struct sockaddr_in *) &ifr.ifr_addr; @@ -159,7 +159,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, buf->flags |= (1L << GLIBTOP_NETLOAD_ADDRESS); } - strcpy (ifr.ifr_name, interface); + g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name); if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) { struct sockaddr_in addr = *(struct sockaddr_in *) &ifr.ifr_addr; @@ -167,7 +167,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET); } - strcpy (ifr.ifr_name, interface); + g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name); if (!ioctl (skfd, SIOCGIFMTU, &ifr)) { buf->mtu = ifr.ifr_mtu; buf->flags |= (1L << GLIBTOP_NETLOAD_MTU); diff --git a/sysdeps/linux/procmap.c b/sysdeps/linux/procmap.c index 3912c210..0cf34ced 100644 --- a/sysdeps/linux/procmap.c +++ b/sysdeps/linux/procmap.c @@ -120,9 +120,8 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid) (guint64) dev_minor; entry_list [n].inode = (guint64) inode; - strncpy (entry_list [n].filename, fn, GLIBTOP_MAP_FILENAME_LEN); - entry_list [n].filename [GLIBTOP_MAP_FILENAME_LEN] = 0; - + g_strlcpy (entry_list [n].filename, fn, sizeof entry_list [n].filename); + n++; } while (rv != EOF && rv && fn [0] != EOF); diff --git a/sysdeps/linux/procstate.c b/sysdeps/linux/procstate.c index 39d93319..e3bb9221 100644 --- a/sysdeps/linux/procstate.c +++ b/sysdeps/linux/procstate.c @@ -86,8 +86,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid) if (*p++ != '(') glibtop_error_r (server, "Bad data in /proc/%d/stat", pid); - strncpy (buf->cmd, p, sizeof (buf->cmd)-1); - buf->cmd [sizeof (buf->cmd)-1] = 0; + g_strlcpy (buf->cmd, p, sizeof buf->cmd); buf->flags |= _glibtop_sysdeps_proc_state; } diff --git a/sysdeps/linux/sysinfo.c b/sysdeps/linux/sysinfo.c index d4a19bf3..157936a5 100644 --- a/sysdeps/linux/sysinfo.c +++ b/sysdeps/linux/sysinfo.c @@ -33,14 +33,15 @@ static glibtop_sysinfo sysinfo; static void init_sysinfo (glibtop *server) { - char buffer [BUFSIZ]; - static int init = 0; + static gboolean is_init = FALSE; + + char buffer [BUFSIZ]; glibtop_entry *cpuinfo = NULL; FILE *f; - if (init) return; + if (is_init) return; - init = TRUE; + is_init = TRUE; glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0); |