This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] Fix constness problem in ioscm_make_gdb_stdio_port
- From: Simon Marchi <simark at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 26 Oct 2015 12:43:12 -0000
- Subject: [binutils-gdb] Fix constness problem in ioscm_make_gdb_stdio_port
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=48ffa2b8cd986527a41654c3b27755bbf6762048
commit 48ffa2b8cd986527a41654c3b27755bbf6762048
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date: Mon Oct 26 08:41:38 2015 -0400
Fix constness problem in ioscm_make_gdb_stdio_port
ioscm_make_gdb_stdio_port passes const char pointers (literal strings) to
scm_mode_bits, which takes a non-const char pointer. Ideally, we would
change scm_mode_bits to take a const char pointer, but it's not part of
an API we control.
Instead, it's easy enough to build the string to pass to scm_mode_bits in
a (non-const) char array and pass that.
gdb/ChangeLog:
* guile/scm-ports.c (ioscm_make_gdb_stdio_port): Pass non-const
char pointer to scm_mode_bits.
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/guile/scm-ports.c | 15 +++++++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index da09f5b..f26f233 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2015-10-26 Simon Marchi <simon.marchi@polymtl.ca>
+ * guile/scm-ports.c (ioscm_make_gdb_stdio_port): Pass non-const
+ char pointer to scm_mode_bits.
+
+2015-10-26 Simon Marchi <simon.marchi@polymtl.ca>
+
* symtab.c (default_make_symbol_completion_list_break_on_1): Add
cast.
diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
index 10d7ee2..5d529b3 100644
--- a/gdb/guile/scm-ports.c
+++ b/gdb/guile/scm-ports.c
@@ -357,29 +357,36 @@ ioscm_init_stdio_buffers (SCM port, long mode_bits)
static SCM
ioscm_make_gdb_stdio_port (int fd)
{
- int is_a_tty = isatty (fd);
const char *name;
long mode_bits;
SCM port;
+ char buf[3];
+
+ memset (buf, 0, sizeof (buf));
switch (fd)
{
case 0:
name = input_port_name;
- mode_bits = scm_mode_bits (is_a_tty ? "r0" : "r");
+ buf[0] = 'r';
break;
case 1:
name = output_port_name;
- mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w");
+ buf[0] = 'w';
break;
case 2:
name = error_port_name;
- mode_bits = scm_mode_bits (is_a_tty ? "w0" : "w");
+ buf[0] = 'w';
break;
default:
gdb_assert_not_reached ("bad stdio file descriptor");
}
+ if (isatty (fd))
+ buf[1] = '0';
+
+ mode_bits = scm_mode_bits (buf);
+
port = ioscm_open_port (stdio_port_desc, mode_bits);
scm_set_port_filename_x (port, gdbscm_scm_from_c_string (name));