aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/io/open.c
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2011-04-16 20:43:03 +0300
committerJanne Blomqvist <jb@gcc.gnu.org>2011-04-16 20:43:03 +0300
commitd30fe1c5cdc98c83c1d29d6b20f88a13328faddd (patch)
treea18b46c3ac70b0e29558cbe228eaa2af23e758b9 /libgfortran/io/open.c
parent9c575e20c33a032619b063d243f6e7320fcda878 (diff)
downloadgcc-d30fe1c5cdc98c83c1d29d6b20f88a13328faddd.zip
gcc-d30fe1c5cdc98c83c1d29d6b20f88a13328faddd.tar.gz
gcc-d30fe1c5cdc98c83c1d29d6b20f88a13328faddd.tar.bz2
Replace sprintf with snprintf
From-SVN: r172590
Diffstat (limited to 'libgfortran/io/open.c')
-rw-r--r--libgfortran/io/open.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c
index d7448c0..bcf7941 100644
--- a/libgfortran/io/open.c
+++ b/libgfortran/io/open.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
+/* Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
Free Software Foundation, Inc.
Contributed by Andy Vaught
F2003 I/O support contributed by Jerry DeLisle
@@ -467,12 +467,8 @@ new_unit (st_parameter_open *opp, gfc_unit *u, unit_flags * flags)
break;
opp->file = tmpname;
-#ifdef HAVE_SNPRINTF
opp->file_len = snprintf(opp->file, sizeof (tmpname), "fort.%d",
(int) opp->common.unit);
-#else
- opp->file_len = sprintf(opp->file, "fort.%d", (int) opp->common.unit);
-#endif
break;
default:
@@ -504,26 +500,29 @@ new_unit (st_parameter_open *opp, gfc_unit *u, unit_flags * flags)
if (s == NULL)
{
char *path, *msg;
+ size_t msglen;
path = (char *) gfc_alloca (opp->file_len + 1);
- msg = (char *) gfc_alloca (opp->file_len + 51);
+ msglen = opp->file_len + 51;
+ msg = (char *) gfc_alloca (msglen);
unpack_filename (path, opp->file, opp->file_len);
switch (errno)
{
case ENOENT:
- sprintf (msg, "File '%s' does not exist", path);
+ snprintf (msg, msglen, "File '%s' does not exist", path);
break;
case EEXIST:
- sprintf (msg, "File '%s' already exists", path);
+ snprintf (msg, msglen, "File '%s' already exists", path);
break;
case EACCES:
- sprintf (msg, "Permission denied trying to open file '%s'", path);
+ snprintf (msg, msglen,
+ "Permission denied trying to open file '%s'", path);
break;
case EISDIR:
- sprintf (msg, "'%s' is a directory", path);
+ snprintf (msg, msglen, "'%s' is a directory", path);
break;
default: