From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16639 invoked by alias); 4 Feb 2010 21:58:30 -0000 Received: (qmail 16630 invoked by uid 22791); 4 Feb 2010 21:58:30 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 04 Feb 2010 21:58:24 +0000 Received: from kpbe17.cbf.corp.google.com (kpbe17.cbf.corp.google.com [172.25.105.81]) by smtp-out.google.com with ESMTP id o14LwKf8028095 for ; Thu, 4 Feb 2010 21:58:21 GMT Received: from ewy7 (ewy7.prod.google.com [10.241.103.7]) by kpbe17.cbf.corp.google.com with ESMTP id o14LwJ3o012833 for ; Thu, 4 Feb 2010 13:58:19 -0800 Received: by ewy7 with SMTP id 7so1390551ewy.10 for ; Thu, 04 Feb 2010 13:58:19 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.88.207 with SMTP id a57mr976376wef.200.1265320698605; Thu, 04 Feb 2010 13:58:18 -0800 (PST) In-Reply-To: <201002040207.39493.vapier@gentoo.org> References: <201002040207.39493.vapier@gentoo.org> Date: Thu, 04 Feb 2010 21:58:00 -0000 Message-ID: Subject: Re: [patch] check return value of do_write in sim_load_file() From: Doug Evans To: Mike Frysinger Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-IsSubscribed: yes 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: 2010-02/txt/msg00142.txt.bz2 On Wed, Feb 3, 2010 at 11:07 PM, Mike Frysinger wrote: > if the do_write function (which is the real meat of sim_load_file()) fail= s, > nothing is displayed in the load output to indicate a problem. =A0so chec= k the > return value before declaring everything peachy. > > 2010-02-04 =A0Mike Frysinger =A0 > > =A0 =A0 =A0 =A0* sim-load.c (sim_load_file): Check do_write() return valu= e. > > RCS file: /cvs/src/src/sim/common/sim-load.c,v > retrieving revision 1.14 > diff -u -p -r1.14 sim-load.c > --- sim/common/sim-load.c =A0 =A0 =A0 1 Jan 2010 10:03:27 -0000 =A0 =A0 = =A0 1.14 > +++ sim/common/sim-load.c =A0 =A0 =A0 4 Feb 2010 07:02:42 -0000 > @@ -140,8 +140,10 @@ sim_load_file (sd, myname, callback, pro > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0 =A0 =A0 =A0data_count +=3D size; > =A0 =A0 =A0 =A0 =A0 =A0 =A0bfd_get_section_contents (result_bfd, s, buffe= r, 0, size); > - =A0 =A0 =A0 =A0 =A0 =A0 do_write (sd, lma, buffer, size); > - =A0 =A0 =A0 =A0 =A0 =A0 found_loadable_section =3D 1; > + =A0 =A0 =A0 =A0 =A0 =A0 if (do_write (sd, lma, buffer, size) !=3D size) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 eprintf (callback, "\tloading section faile= d\n"); > + =A0 =A0 =A0 =A0 =A0 =A0 else > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 found_loadable_section =3D 1; > =A0 =A0 =A0 =A0 =A0 =A0 =A0free (buffer); > =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0} > If there's an error loading a section I think it would be better to fail the entire call. How about something like if (do_write (sd, lma, buffer, size) !=3D size) { eprintf (callback, "%s: error loading section %s\n", myname, bfd_get_section_name (result_bfd, s)); /* Only close if we opened it. */ if (prog_bfd =3D=3D NULL) bfd_close (result_bfd); free (buffer); return NULL; }