Package: gdb
Version: 6.3-5
Severity: minor
Tags: patch


Consider the following gdb session:

----> gdb session <----
$ gdb
GNU gdb 6.3-debian
[...]
(gdb) printf "%lld\n",1
1
(gdb) printf "%yd\n",1
%yd
(gdb) printf "%qd\n",1
/nevyn/local/gdb/gdb-6.3/gdb/utils.c:1013: internal-error: virtual memory exhausted.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
----> end of gdb session <----


The input to this session is precicely the one used to trigger bug #186037. The error message ("virtual memory exhausted"), however, has become different since gdb version 5.3 due to a bug in the function xstrvprintf() at gdb/utils.c:1120 which is unrelated to bug #186037 (in particular, other bugs may be affected as well).

The function xstrvprintf() (gdb/utils.c:1120) looks as follows:

---> snip <---
char *
xstrvprintf (const char *format, va_list ap)
{
  char *ret = NULL;
  int status = vasprintf (&ret, format, ap);
  /* NULL is returned when there was a memory allocation
     problem.  */
  if (ret == NULL)
    nomem (0);
  /* A negative status (the printed length) with a non-NULL
     buffer should never happen, but just to be sure.  */
  if (status < 0)
    internal_error (__FILE__, __LINE__,
                    "vasprintf call failed (errno %d)", errno);
  return ret;
}
---> snap <---

According to the libc info file however, the correct way to check if a call to vasprintf failed is to simply check for a negative return value. Furthermore, vasprintf does not seem to set errno. This leads to the wrong error message above.

I therefore propose to remove the ret==NULL check and the reference to errno (see attached patch).

Of course this does not fix #186037, but restores it to its former behaviour.


Regards, Alexander
--- utils.c     2005-02-22 13:28:48.000000000 +0000
+++ utils.c.new 2005-02-22 18:09:53.000000000 +0000
@@ -1120,16 +1120,12 @@
 char *
 xstrvprintf (const char *format, va_list ap)
 {
-  char *ret = NULL;
+  char *ret;
   int status = vasprintf (&ret, format, ap);
-  /* NULL is returned when there was a memory allocation problem.  */
-  if (ret == NULL)
-    nomem (0);
-  /* A negative status (the printed length) with a non-NULL buffer
-     should never happen, but just to be sure.  */
+  /* Negative status indicates error  */
   if (status < 0)
     internal_error (__FILE__, __LINE__,
-                   "vasprintf call failed (errno %d)", errno);
+                   "vasprintf call failed");
   return ret;
 }
 

Reply via email to