From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6771 invoked by alias); 12 Nov 2013 23:44:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 6762 invoked by uid 89); 12 Nov 2013 23:44:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.8 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RDNS_NONE,SPF_PASS autolearn=no version=3.3.2 X-HELO: dub0-omc1-s9.dub0.hotmail.com Received: from Unknown (HELO dub0-omc1-s9.dub0.hotmail.com) (157.55.0.208) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Nov 2013 23:44:14 +0000 Received: from DUB122-W11 ([157.55.0.239]) by dub0-omc1-s9.dub0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 12 Nov 2013 15:44:06 -0800 X-TMN: [aErUWipslFkQjUif5MR574meD7BODW5r] Message-ID: From: Bernd Edlinger To: Dodji Seketeli , Jakub Jelinek CC: GCC Patches , Tom Tromey , =?iso-8859-1?B?TWFudWVsIEzzcGV6LUli4fFleg==?= Subject: RE: [PATCH] preprocessor/58580 - preprocessor goes OOM with warning for zero literals Date: Wed, 13 Nov 2013 05:10:00 -0000 In-Reply-To: <878uwt63e2.fsf@redhat.com> References: ,<20131031144309.GR27813@tucnak.zalov.cz> <87y559xz7y.fsf@redhat.com>,<20131031173649.GW27813@tucnak.zalov.cz> <87zjpbb5qu.fsf@redhat.com>,<20131111142159.GZ27813@tucnak.zalov.cz> <878uwuap4f.fsf@redhat.com>,<878uwt63e2.fsf@redhat.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-SW-Source: 2013-11/txt/msg01383.txt.bz2 Hi, On Tue, 12 Nov 2013 16:33:41, Dodji Seketeli wrote: > > +/* Reads the next line from FILE into *LINE. If *LINE is too small > + (or NULL) it is allocated (or extended) to have enough space to > + containe the line. *LINE_LENGTH must contain the size of the > + initial*LINE buffer. It's then updated by this function to the > + actual length of the returned line. Note that the returned line > + can contain several zero bytes. Also note that the returned string > + is allocated in static storage that is going to be re-used by > + subsequent invocations of read_line. */ > + > +static bool > +read_next_line (fcache *cache, char ** line, ssize_t *line_len) > +{ > + char *l =3D NULL; > + ssize_t len =3D get_next_line (cache, &l); > + > + if (len> 0) > + { > + if (*line =3D=3D NULL) > { > - string[pos + len - 1] =3D 0; > - return string; > + *line =3D XNEWVEC (char, len); > + *line_len =3D len; > } > - pos +=3D len; > - string =3D XRESIZEVEC (char, string, string_len * 2); > - string_len *=3D 2; > + else > + if (*line_len < len) > + *line =3D XRESIZEVEC (char, *line, len); > + > + memmove (*line, l, len); > + (*line)[len - 1] =3D '\0'; > + *line_len =3D --len; Generally, I would prefer to use memcpy, if it is clear that the memory does not overlap. You copy one char too much and set it to zero? Using -- on a value that goes out of scope looks awkward IMHO. Bernd. > + return true; > } > - > - return pos ? string : NULL; > + > + return false; > +}=20=09=09=20=09=20=20=20=09=09=20=20