From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11116 invoked by alias); 13 Mar 2013 21:52:08 -0000 Received: (qmail 11105 invoked by uid 22791); 13 Mar 2013 21:52:06 -0000 X-SWARE-Spam-Status: No, hits=-8.9 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Mar 2013 21:51:56 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2DLptA4011680 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Mar 2013 17:51:55 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2DLpsej000562; Wed, 13 Mar 2013 17:51:54 -0400 Message-ID: <5140F4F9.9050000@redhat.com> Date: Wed, 13 Mar 2013 21:52:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130219 Thunderbird/17.0.3 MIME-Version: 1.0 To: Tom Tromey CC: gdb-patches@sourceware.org Subject: Re: [COMMIT PATCH] More invalid pointer to pointer conversions. References: <20130313164801.25932.31237.stgit@brno.lan> <87r4jjb3p7.fsf@fleche.redhat.com> <5140BD84.7080708@redhat.com> In-Reply-To: <5140BD84.7080708@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 X-SW-Source: 2013-03/txt/msg00612.txt.bz2 On 03/13/2013 05:55 PM, Pedro Alves wrote: > On 03/13/2013 05:38 PM, Tom Tromey wrote: > >> Pedro> - displacement = strtol (tmp, (char **) &tmp, 10); >> Pedro> + displacement = strtol (tmp, &endp, 10); >> Pedro> + tmp = endp; >> >> I saw this in Keith's patch, too, and I was wondering if we should have >> a strtol_const convenience function. > > Yeah, I wondered the same. I don't mind either way, actually. > > ( Read, I don't want it enough to add it myself :-) ) > One thought occurred to me now though. Every place that is doing: char *tmp; long l = strtol (tmp, &tmp, 0); or: (const)? char *tmp; char *endp; displacement = strtol (tmp, &endp, 10); tmp = endp; or the potential: const char *tmp; long l = strtol_const (tmp, &tmp, 0); all suffer from the same problem -- they're not really checking for strtol junk input / overflow. That'd always go: l = strtol (tmp, &endp, 10); // --> here <-- tmp = endp; Given that for proper error handling you always need a separate endp, strtol_const doesn't feel like it adds much if anything in practice. Perhaps instead we should either fix all the strtol call sites for error handling, or even come up with (a) throwing variant(s). See e.g., xml_parse_unsigned_integer and gdb_xml_parse_ulongest for possible interfaces. (I note ERANGE handling is missing there too). -- Pedro Alves