public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix GDBHISTSIZE test failure on i686
@ 2015-06-23 14:31 Patrick Palka
  2015-06-23 14:46 ` Patrick Palka
  2015-06-23 17:19 ` Pedro Alves
  0 siblings, 2 replies; 5+ messages in thread
From: Patrick Palka @ 2015-06-23 14:31 UTC (permalink / raw)
  To: gdb-patches; +Cc: Patrick Palka

The test

  test_histsize_history_setting "99999999999999999999999999999999999" "unlimited"

was failing on i686 because the condition in init_history() for
determining whether to map a large GDBHISTSIZE value to infinity was

  long var = strtol (tmpenv);
  if (var > INT_MAX)
    history_size = unlimited;

but this condition is never true on i686 because INT_MAX == LONG_MAX.
So in order to properly map large out-of-range values of GDBHISTSIZE to
infinity on targets where LONG_MAX > INT_MAX as well as on i686, we have
to instead change the above condition to

  if (var > INT_MAX
      || (var == INT_MAX && errno == ERANGE))
    history_size = unlimited;

[ I did not test this patch on i686 because I don't have access to
  such a machine.  But the patch seems straightforward enough... ]

gdb/ChangeLog:

	* top.c (init_history): Look at the errno set by strtol to
	properly map large GDBHISTSIZE values to infinity.
---
 gdb/top.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gdb/top.c b/gdb/top.c
index 5114c2e..afb14be 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1734,10 +1734,12 @@ init_history (void)
   if (tmpenv)
     {
       long var;
+      int saved_errno;
       char *endptr;
 
       tmpenv = skip_spaces (tmpenv);
       var = strtol (tmpenv, &endptr, 10);
+      saved_errno = errno;
       endptr = skip_spaces (endptr);
 
       /* If GDBHISTSIZE is non-numeric then ignore it.  If GDBHISTSIZE is the
@@ -1749,7 +1751,12 @@ init_history (void)
 	;
       else if (*tmpenv == '\0'
 	       || var < 0
-	       || var > INT_MAX)
+	       || var > INT_MAX
+	       /* On targets where INT_MAX == LONG_MAX, we have to look at
+		  the errno set by strtol to distinguish between a value that
+		  is exactly INT_MAX and an overflowing value that was clamped
+		  to INT_MAX.  */
+	       || (var == INT_MAX && saved_errno == ERANGE))
 	history_size_setshow_var = -1;
       else
 	history_size_setshow_var = var;
-- 
2.4.4.410.g43ed522.dirty

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-23 19:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-23 14:31 [PATCH] Fix GDBHISTSIZE test failure on i686 Patrick Palka
2015-06-23 14:46 ` Patrick Palka
2015-06-23 17:19 ` Pedro Alves
2015-06-23 17:42   ` Doug Evans
2015-06-23 19:36   ` Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).