From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32529 invoked by alias); 6 Jan 2015 15:09:34 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 32515 invoked by uid 89); 6 Jan 2015 15:09:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 06 Jan 2015 15:09:27 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 98220116466 for ; Tue, 6 Jan 2015 10:09:25 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id DK8sd1fCJ6yj for ; Tue, 6 Jan 2015 10:09:25 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 2E411116463 for ; Tue, 6 Jan 2015 10:09:23 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id E0F704100E; Tue, 6 Jan 2015 19:09:18 +0400 (RET) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [pushed] gdb/python: exception trying to create empty array Date: Tue, 06 Jan 2015 15:09:00 -0000 Message-Id: <1420556955-13827-1-git-send-email-brobecker@adacore.com> X-SW-Source: 2015-01/txt/msg00071.txt.bz2 Hello, The following python command fails: (gdb) python print gdb.lookup_type('char').array(1, 0) Traceback (most recent call last): File "", line 1, in ValueError: Array length must not be negative Error while executing Python code. The above is trying to create an empty array, which is fairly command in Ada. gdb/ChangeLog: * python/py-type.c (typy_array_1): Do not raise negative-length exception if N2 is equal to N1 - 1. gdb/testsuite/ChangeLog: * gdb.python/py-type.exp: Add a couple test about empty array creation, and negative-length array creation. Tested on x86_64-linux, no regression. Pushed a obvious. Thank you, -- Joel PS: There is the same error in guile, and I will push a patch momentarily. --- gdb/ChangeLog | 5 +++++ gdb/python/py-type.c | 2 +- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.python/py-type.exp | 6 ++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b3e1263..a6211bf 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2015-01-06 Joel Brobecker + + * python/py-type.c (typy_array_1): Do not raise negative-length + exception if N2 is equal to N1 - 1. + 2015-01-03 Doug Evans * c-exp.y: Whitespace cleanup. diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 54fc30f..8e82c99 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -528,7 +528,7 @@ typy_array_1 (PyObject *self, PyObject *args, int is_vector) n1 = 0; } - if (n2 < n1) + if (n2 < n1 - 1) { PyErr_SetString (PyExc_ValueError, _("Array length must not be negative")); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 374c285..7db0809 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-01-06 Joel Brobecker + + * gdb.python/py-type.exp: Add a couple test about empty + array creation, and negative-length array creation. + 2015-01-02 Doug Evans * gdb.cp/nsalias.exp: Fix output of external/declaration flags. diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index 90de68d..c4c8d9f 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -247,6 +247,12 @@ restart_gdb "${binfile}" # Skip all tests if Python scripting is not enabled. if { [skip_python_tests] } { continue } +gdb_test "python print gdb.lookup_type('char').array(1, 0)" \ + "char \\\[0\\\]" + +gdb_test "python print gdb.lookup_type('char').array(1, -1)" \ + "Array length must not be negative.*" + with_test_prefix "lang_c" { runto_bp "break to inspect struct and array." test_fields "c" -- 1.9.1