This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] getc/putc -Wunused-value warnings in source.c


Hello,

The ppc-aix debugger currently does not build out of the box with
-Werror, yet, but we are close.  One of the issues we have is a
Wunused-value warning when using getc/putc functions.  For instance...

        val = putc ('\n', f);

... triggers the following warning:

        warning: value computed is not used [-Wunused-value]

This is related to the fact that putc is implemented as a macro
on AIX, and that this macro:

>#define putc(__x, __p)  (((!((__p)->_flag & 0xC000)) && \
>                        ((__p)->_flag = ((__p)->_flag  & 0x3FFF) | 0x8000)),\
>                        (--(__p)->_cnt < 0 ? \
>                        __flsbuf((unsigned char) (__x), (__p)) : \

Same thing for getc.

One could easily work around the problem by using fgetc instead of getc,
as done in this patch.  But it's a sure thing that the same problem
will likely reappear again later. To prevent this, we could also poison
putc/getc, but it feels a little unfair to be poisonning perfectly
legal "functions". One option could be to not enable -Wunused-value
on ppc-aix, but then it'd be a shame, since we're so close to a clean
build. The last option could be to #undef getc + #define getc fgetc,
but I do not think that this would be correct, since the man page
indicates that the file might be evaluated multiple time in the case
of the getc macro.

gdb/ChangeLog:

        * source.c (forward_search_command): Replace call to getc
        by call to fgetc.  Add comment explaining why.
        (reverse_search_command): Likewise.

Any thoughts, on this?

Thank you,
-- 
Joel

---
 gdb/source.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/source.c b/gdb/source.c
index a2e957c..204cab1 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1648,7 +1648,9 @@ forward_search_command (char *regex, int from_tty)
       buf = xmalloc (cursize);
       p = buf;
 
-      c = getc (stream);
+      /* On AIX, getc is implemented as a macro that triggers a warning
+	 (-Wunused-value).  So use the fgetc function to avoid it.  */
+      c = fgetc (stream);
       if (c == EOF)
 	break;
       do
@@ -1662,7 +1664,7 @@ forward_search_command (char *regex, int from_tty)
 	      cursize = newsize;
 	    }
 	}
-      while (c != '\n' && (c = getc (stream)) >= 0);
+      while (c != '\n' && (c = fgetc (stream)) >= 0); /* See getc note above. */
 
       /* Remove the \r, if any, at the end of the line, otherwise
          regular expressions that end with $ or \n won't work.  */
@@ -1733,14 +1735,16 @@ reverse_search_command (char *regex, int from_tty)
       char buf[4096];		/* Should be reasonable???  */
       char *p = buf;
 
-      c = getc (stream);
+      /* On AIX, getc is implemented as a macro that triggers a warning
+	 (-Wunused-value).  So use the fgetc function to avoid it.  */
+      c = fgetc (stream);
       if (c == EOF)
 	break;
       do
 	{
 	  *p++ = c;
 	}
-      while (c != '\n' && (c = getc (stream)) >= 0);
+      while (c != '\n' && (c = fgetc (stream)) >= 0);
 
       /* Remove the \r, if any, at the end of the line, otherwise
          regular expressions that end with $ or \n won't work.  */
-- 
1.7.0.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]