This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[COMMIT] More s/sprintf/snprintf/
- From: Mark Kettenis <kettenis at gnu dot org>
- To: gdb-patches at sourceware dot org
- Date: Sun, 13 Mar 2005 23:06:23 +0100 (CET)
- Subject: [COMMIT] More s/sprintf/snprintf/
This one attacks a for xxx_pid_to_str function. I changed the
capitalization of the output of remote_pid_to_str to match the others.
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@elgar.gnu.org>
* inf-ttrace.c (inf_ttrace_pid_to_str): Use snprintf instead of
sprintf.
* target.c (normal_pid_to_str): Likewise.
* remote.c (remote_pid_to_str): Use snprint instead of sprintf.
Change capitalization of "thread". Use ptid_get_pid instead of
GETPID.
Index: inf-ttrace.c
===================================================================
RCS file: /cvs/src/src/gdb/inf-ttrace.c,v
retrieving revision 1.8
diff -u -p -r1.8 inf-ttrace.c
--- inf-ttrace.c 12 Feb 2005 00:39:19 -0000 1.8
+++ inf-ttrace.c 13 Mar 2005 20:44:51 -0000
@@ -908,9 +908,12 @@ inf_ttrace_pid_to_str (ptid_t ptid)
{
pid_t pid = ptid_get_pid (ptid);
lwpid_t lwpid = ptid_get_lwp (ptid);
- static char buf[80];
+ static char buf[128];
+ int size;
- sprintf (buf, "process %ld, lwp %ld", (long)pid, (long)lwpid);
+ size = snprintf (buf, sizeof buf, "process %ld, lwp %ld",
+ (long)pid, (long)lwpid);
+ gdb_assert (size < sizeof buf);
return buf;
}
Index: target.c
===================================================================
RCS file: /cvs/src/src/gdb/target.c,v
retrieving revision 1.102
diff -u -p -r1.102 target.c
--- target.c 4 Mar 2005 17:47:59 -0000 1.102
+++ target.c 13 Mar 2005 20:44:53 -0000
@@ -1803,15 +1803,17 @@ store_waitstatus (struct target_waitstat
int (*target_activity_function) (void);
int target_activity_fd;
-/* Convert a normal process ID to a string. Returns the string in a static
- buffer. */
+/* Convert a normal process ID to a string. Returns the string in a
+ static buffer. */
char *
normal_pid_to_str (ptid_t ptid)
{
- static char buf[30];
+ static char buf[32];
+ int size;
- sprintf (buf, "process %d", PIDGET (ptid));
+ size = snprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid));
+ gdb_assert (size < sizeof buf);
return buf;
}
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.177
diff -u -p -r1.177 remote.c
--- remote.c 8 Mar 2005 14:30:46 -0000 1.177
+++ remote.c 13 Mar 2005 20:44:56 -0000
@@ -5322,9 +5322,11 @@ Fetch and print the remote list of threa
static char *
remote_pid_to_str (ptid_t ptid)
{
- static char buf[30];
+ static char buf[32];
+ int size;
- sprintf (buf, "Thread %d", PIDGET (ptid));
+ size = snprintf (buf, sizeof buf, "thread %d", ptid_get_pid (ptid));
+ gdb_assert (size < sizeof buf);
return buf;
}