public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA] use xsnprintf instead of snprintf.
@ 2010-08-31 19:07 Joel Brobecker
  2010-08-31 19:49 ` Pedro Alves
  2010-09-01  1:56 ` Joel Brobecker
  0 siblings, 2 replies; 3+ messages in thread
From: Joel Brobecker @ 2010-08-31 19:07 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

snprintf is not available on LynxOS (bloody OS :-(), so I changed
the calls to snprintf to calls to xsnprintf, which should be strictly
equivalent.

gdb/gdbserver/ChangeLog:

        * utils.c (xsnprintf): Make non-static.
        * server.h: Add xsnprintf declaration.
        * linux-low.c, nto-low.c, target.c, thread-db.c, tracepoint.c:
        replace calls to snprintf by calls to xsnprintf throughout.

Tested on x86_64-linux. Any objection?

---
 gdb/gdbserver/linux-low.c  |    2 +-
 gdb/gdbserver/nto-low.c    |    2 +-
 gdb/gdbserver/server.h     |    2 ++
 gdb/gdbserver/target.c     |   16 ++++++++--------
 gdb/gdbserver/thread-db.c  |    4 ++--
 gdb/gdbserver/tracepoint.c |    8 ++++----
 gdb/gdbserver/utils.c      |    2 +-
 7 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 714dac3..f2177ff 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -4310,7 +4310,7 @@ linux_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int len)
   int fd, n;
   int pid = lwpid_of (get_thread_lwp (current_inferior));
 
-  snprintf (filename, sizeof filename, "/proc/%d/auxv", pid);
+  xsnprintf (filename, sizeof filename, "/proc/%d/auxv", pid);
 
   fd = open (filename, O_RDONLY);
   if (fd < 0)
diff --git a/gdb/gdbserver/nto-low.c b/gdb/gdbserver/nto-low.c
index 0c54b90..e094e28 100644
--- a/gdb/gdbserver/nto-low.c
+++ b/gdb/gdbserver/nto-low.c
@@ -174,7 +174,7 @@ do_attach (pid_t pid)
       close (nto_inferior.ctl_fd);
       init_nto_inferior (&nto_inferior);
     }
-  snprintf (nto_inferior.nto_procfs_path, PATH_MAX - 1, "/proc/%d/as", pid);
+  xsnprintf (nto_inferior.nto_procfs_path, PATH_MAX - 1, "/proc/%d/as", pid);
   nto_inferior.ctl_fd = open (nto_inferior.nto_procfs_path, O_RDWR);
   if (nto_inferior.ctl_fd == -1)
     {
diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h
index b401960..286c80a 100644
--- a/gdb/gdbserver/server.h
+++ b/gdb/gdbserver/server.h
@@ -473,6 +473,8 @@ void *xmalloc (size_t) ATTR_MALLOC;
 void *xrealloc (void *, size_t);
 void *xcalloc (size_t, size_t) ATTR_MALLOC;
 char *xstrdup (const char *) ATTR_MALLOC;
+int xsnprintf (char *str, size_t size, const char *format, ...)
+  ATTR_FORMAT (printf, 3, 4);;
 void freeargv (char **argv);
 void perror_with_name (const char *string);
 void error (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
diff --git a/gdb/gdbserver/target.c b/gdb/gdbserver/target.c
index 4fc8c07..21dd377 100644
--- a/gdb/gdbserver/target.c
+++ b/gdb/gdbserver/target.c
@@ -139,18 +139,18 @@ target_pid_to_str (ptid_t ptid)
   static char buf[80];
 
   if (ptid_equal (ptid, minus_one_ptid))
-    snprintf (buf, sizeof (buf), "<all threads>");
+    xsnprintf (buf, sizeof (buf), "<all threads>");
   else if (ptid_equal (ptid, null_ptid))
-    snprintf (buf, sizeof (buf), "<null thread>");
+    xsnprintf (buf, sizeof (buf), "<null thread>");
   else if (ptid_get_tid (ptid) != 0)
-    snprintf (buf, sizeof (buf), "Thread %d.0x%lx",
-	      ptid_get_pid (ptid), ptid_get_tid (ptid));
+    xsnprintf (buf, sizeof (buf), "Thread %d.0x%lx",
+	       ptid_get_pid (ptid), ptid_get_tid (ptid));
   else if (ptid_get_lwp (ptid) != 0)
-    snprintf (buf, sizeof (buf), "LWP %d.%ld",
-	      ptid_get_pid (ptid), ptid_get_lwp (ptid));
+    xsnprintf (buf, sizeof (buf), "LWP %d.%ld",
+	       ptid_get_pid (ptid), ptid_get_lwp (ptid));
   else
-    snprintf (buf, sizeof (buf), "Process %d",
-	      ptid_get_pid (ptid));
+    xsnprintf (buf, sizeof (buf), "Process %d",
+	       ptid_get_pid (ptid));
 
   return buf;
 }
diff --git a/gdb/gdbserver/thread-db.c b/gdb/gdbserver/thread-db.c
index 86c4e18..372cdbc 100644
--- a/gdb/gdbserver/thread-db.c
+++ b/gdb/gdbserver/thread-db.c
@@ -150,7 +150,7 @@ thread_db_err_str (td_err_e err)
       return "version mismatch between libthread_db and libpthread";
 #endif
     default:
-      snprintf (buf, sizeof (buf), "unknown thread_db error '%d'", err);
+      xsnprintf (buf, sizeof (buf), "unknown thread_db error '%d'", err);
       return buf;
     }
 }
@@ -176,7 +176,7 @@ thread_db_state_str (td_thr_state_e state)
     case TD_THR_STOPPED_ASLEEP:
       return "stopped by debugger AND blocked";
     default:
-      snprintf (buf, sizeof (buf), "unknown thread_db state %d", state);
+      xsnprintf (buf, sizeof (buf), "unknown thread_db state %d", state);
       return buf;
     }
 }
diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index c2d7da8..f068ce4 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -6723,7 +6723,7 @@ gdb_ust_connect_sync_socket (int pid)
   int res, fd;
   char path[UNIX_PATH_MAX];
 
-  res = snprintf (path, UNIX_PATH_MAX, "%s/gdb_ust%d", SOCK_DIR, pid);
+  res = xsnprintf (path, UNIX_PATH_MAX, "%s/gdb_ust%d", SOCK_DIR, pid);
   if (res >= UNIX_PATH_MAX)
     {
       trace_debug ("string overflow allocating socket name");
@@ -6739,7 +6739,7 @@ gdb_ust_connect_sync_socket (int pid)
 
   addr.sun_family = AF_UNIX;
 
-  res = snprintf (addr.sun_path, UNIX_PATH_MAX, "%s", path);
+  res = xsnprintf (addr.sun_path, UNIX_PATH_MAX, "%s", path);
   if (res >= UNIX_PATH_MAX)
     {
       warning ("string overflow allocating socket name\n");
@@ -6964,8 +6964,8 @@ gdb_ust_socket_init (void)
   int result, fd;
   char name[UNIX_PATH_MAX];
 
-  result = snprintf (name, UNIX_PATH_MAX, "%s/gdb_ust%d",
-		     SOCK_DIR, getpid ());
+  result = xsnprintf (name, UNIX_PATH_MAX, "%s/gdb_ust%d",
+		      SOCK_DIR, getpid ());
   if (result >= UNIX_PATH_MAX)
     {
       trace_debug ("string overflow allocating socket name");
diff --git a/gdb/gdbserver/utils.c b/gdb/gdbserver/utils.c
index 4c047e0..7de086c 100644
--- a/gdb/gdbserver/utils.c
+++ b/gdb/gdbserver/utils.c
@@ -244,7 +244,7 @@ get_cell (void)
 /* Stdarg wrapper around vsnprintf.
    SIZE is the size of the buffer pointed to by STR.  */
 
-static int
+int
 xsnprintf (char *str, size_t size, const char *format, ...)
 {
   va_list args;
-- 
1.7.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] use xsnprintf instead of snprintf.
  2010-08-31 19:07 [RFA] use xsnprintf instead of snprintf Joel Brobecker
@ 2010-08-31 19:49 ` Pedro Alves
  2010-09-01  1:56 ` Joel Brobecker
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2010-08-31 19:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

On Tuesday 31 August 2010 20:06:54, Joel Brobecker wrote:
> Tested on x86_64-linux. Any objection?

Not from me.

-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] use xsnprintf instead of snprintf.
  2010-08-31 19:07 [RFA] use xsnprintf instead of snprintf Joel Brobecker
  2010-08-31 19:49 ` Pedro Alves
@ 2010-09-01  1:56 ` Joel Brobecker
  1 sibling, 0 replies; 3+ messages in thread
From: Joel Brobecker @ 2010-09-01  1:56 UTC (permalink / raw)
  To: gdb-patches

> gdb/gdbserver/ChangeLog:
> 
>         * utils.c (xsnprintf): Make non-static.
>         * server.h: Add xsnprintf declaration.
>         * linux-low.c, nto-low.c, target.c, thread-db.c, tracepoint.c:
>         replace calls to snprintf by calls to xsnprintf throughout.

Checked in :).

-- 
Joel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-09-01  1:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-31 19:07 [RFA] use xsnprintf instead of snprintf Joel Brobecker
2010-08-31 19:49 ` Pedro Alves
2010-09-01  1:56 ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).