This is the mail archive of the gdb-patches@sources.redhat.com 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]

[PATCH] Fix invalid use of va_list


Hello,

gdb crashes on s390 when the user answers a (y or n) question with
something else.  This is caused by the 'query' function reusing a
va_list variable initialized only once multiple times.

This is not allowed according to the C standard (C99 7.15.3), and
in fact doesn't work on platforms that define va_list as an array
type.

The patch below changes query to reinitialize the va_list variable
with va_start before each use.

Tested on s390-ibm-linux.

ChangeLog:

	* utils.c (query): Do not use a va_list variable multiple times.

Index: gdb/utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.118
diff -c -p -r1.118 utils.c
*** gdb/utils.c	28 Feb 2004 18:04:37 -0000	1.118
--- gdb/utils.c	30 Mar 2004 12:55:04 -0000
*************** query (const char *ctlstr, ...)
*** 1270,1279 ****
    int ans2;
    int retval;
  
-   va_start (args, ctlstr);
- 
    if (query_hook)
      {
        return query_hook (ctlstr, args);
      }
  
--- 1270,1278 ----
    int ans2;
    int retval;
  
    if (query_hook)
      {
+       va_start (args, ctlstr);
        return query_hook (ctlstr, args);
      }
  
*************** query (const char *ctlstr, ...)
*** 1289,1295 ****
--- 1288,1296 ----
        if (annotation_level > 1)
  	printf_filtered ("\n\032\032pre-query\n");
  
+       va_start (args, ctlstr);
        vfprintf_filtered (gdb_stdout, ctlstr, args);
+       va_end (args);
        printf_filtered ("(y or n) ");
  
        if (annotation_level > 1)
-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de


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