public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH] Replace sprintf with xsnprintf
Date: Tue, 17 Dec 2013 12:58:00 -0000	[thread overview]
Message-ID: <1387284991-28208-1-git-send-email-yao@codesourcery.com> (raw)

Hi,
When working on something else, I happen to see some usages of sprintf
in linux-nat.c.  This patch is to replace sprintf with xsnprintf in
linux-nat.c

gdb:

2013-12-17  Yao Qi  <yao@codesourcery.com>

	* linux-nat.c (linux_proc_xfer_partial): Call xsnprintf instead
	of sprintf.
	(linux_nat_detach, linux_child_pid_to_exec_file): Likewise.
	(linux_proc_pending_signals): Likewise.
---
 gdb/linux-nat.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index d2091ca..a34b29a 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1592,7 +1592,7 @@ linux_nat_detach (struct target_ops *ops, const char *args, int from_tty)
       /* Put the signal number in ARGS so that inf_ptrace_detach will
 	 pass it along with PTRACE_DETACH.  */
       tem = alloca (8);
-      sprintf (tem, "%d", (int) WSTOPSIG (status));
+      xsnprintf (tem, 8, "%d", (int) WSTOPSIG (status));
       args = tem;
       if (debug_linux_nat)
 	fprintf_unfiltered (gdb_stdlog,
@@ -4049,7 +4049,7 @@ linux_child_pid_to_exec_file (int pid)
   make_cleanup (xfree, name2);
   memset (name2, 0, PATH_MAX);
 
-  sprintf (name1, "/proc/%d/exe", pid);
+  xsnprintf (name1, PATH_MAX, "/proc/%d/exe", pid);
   if (readlink (name1, name2, PATH_MAX - 1) > 0)
     return name2;
   else
@@ -4135,7 +4135,8 @@ linux_proc_xfer_partial (struct target_ops *ops, enum target_object object,
 
   /* We could keep this file open and cache it - possibly one per
      thread.  That requires some juggling, but is even faster.  */
-  sprintf (filename, "/proc/%d/mem", ptid_get_pid (inferior_ptid));
+  xsnprintf (filename, sizeof filename, "/proc/%d/mem",
+	     ptid_get_pid (inferior_ptid));
   fd = gdb_open_cloexec (filename, O_RDONLY | O_LARGEFILE, 0);
   if (fd == -1)
     return 0;
@@ -4305,7 +4306,7 @@ linux_proc_pending_signals (int pid, sigset_t *pending,
   sigemptyset (pending);
   sigemptyset (blocked);
   sigemptyset (ignored);
-  sprintf (fname, "/proc/%d/status", pid);
+  xsnprintf (fname, sizeof fname, "/proc/%d/status", pid);
   procfile = gdb_fopen_cloexec (fname, "r");
   if (procfile == NULL)
     error (_("Could not open %s"), fname);
-- 
1.7.7.6

             reply	other threads:[~2013-12-17 12:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17 12:58 Yao Qi [this message]
2013-12-17 15:16 ` Pedro Alves
2013-12-18  3:57   ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1387284991-28208-1-git-send-email-yao@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).