This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFC] Avoid using sprintf in the testsuite
- From: Mark Kettenis <kettenis at gnu dot org>
- To: gdb-patches at sourceware dot org
- Date: Thu, 17 Mar 2005 22:11:49 +0100 (CET)
- Subject: [RFC] Avoid using sprintf in the testsuite
Using sprintf in the testsuite causes problems with the upcoming
OpenBSD 3.7. The warning about its usuge printed by the linker makes
us think the compilation failed. Here's a patch that replaces the
usage of sprintf in gdb.base/fileio.{c,exp} with simple string
concatenation. I'd rather do this instead of using snprintf, since
the latter is not available on HP-UX 10.20.
Objections? Otherwise I'll check this in next weekend.
Mark
Index: testsuite/ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* gdb.base/fileio.c (test_system, test_unlink): Avoid using
sprintf.
* gdb.base/fileio.exp: Adjust line number.
Index: testsuite/gdb.base/fileio.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/fileio.c,v
retrieving revision 1.8
diff -u -p -r1.8 fileio.c
--- testsuite/gdb.base/fileio.c 10 Jan 2005 15:58:23 -0000 1.8
+++ testsuite/gdb.base/fileio.c 17 Mar 2005 21:04:09 -0000
@@ -334,10 +334,10 @@ test_system ()
* Requires test framework to switch on "set remote system-call-allowed 1"
*/
int ret;
- char sys[512];
+ char *sys;
/* This test prepares the directory for test_rename() */
- sprintf (sys, "mkdir -p %s %s", TESTSUBDIR, TESTDIR2);
+ sys = "mkdir -p " TESTSUBDIR " " TESTDIR2;
ret = system (sys);
if (ret == 127)
printf ("system 1: ret = %d /bin/sh unavailable???\n", ret);
@@ -400,21 +400,21 @@ int
test_unlink ()
{
int ret;
- char name[256];
- char sys[512];
+ char *name;
+ char *sys;
/* Test unlink */
errno = 0;
ret = unlink (RENAMED);
printf ("unlink 1: ret = %d, errno = %d %s\n", ret, errno,
strerrno (errno));
+ name = TESTDIR2 "/" FILENAME;
/* No write access */
- sprintf (name, "%s/%s", TESTDIR2, FILENAME);
errno = 0;
ret = open (name, O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR);
if (ret >= 0)
{
- sprintf (sys, "chmod -w %s", TESTDIR2);
+ sys = "chmod -w " TESTDIR2;
ret = system (sys);
if (!ret)
{
Index: testsuite/gdb.base/fileio.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/fileio.exp,v
retrieving revision 1.7
diff -u -p -r1.7 fileio.exp
--- testsuite/gdb.base/fileio.exp 18 Jan 2004 21:17:57 -0000 1.7
+++ testsuite/gdb.base/fileio.exp 17 Mar 2005 21:04:09 -0000
@@ -240,9 +240,9 @@ gdb_test continue \
"Continuing\\..*rename 5:.*ENOENT.*test_rename \\(\\) at.*$srcfile:397.*" \
"Renaming a nonexistant file returns ENOENT"
-send_gdb "tbreak 412\n" ; gdb_expect -re "$gdb_prompt $"
+send_gdb "tbreak 413\n" ; gdb_expect -re "$gdb_prompt $"
gdb_test continue \
-"Continuing\\..*unlink 1:.*OK.*test_unlink \\(\\) at.*$srcfile:412.*" \
+"Continuing\\..*unlink 1:.*OK.*test_unlink \\(\\) at.*$srcfile:413.*" \
"Unlink a file"
send_gdb "tbreak 432\n" ; gdb_expect -re "$gdb_prompt $"