From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 66C4D38515F3; Thu, 12 May 2022 09:44:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66C4D38515F3 From: "fabian@ritter-vogt.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug d/105544] gdc fails to compile d source from stdin Date: Thu, 12 May 2022 09:44:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: d X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fabian@ritter-vogt.de X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ibuclaw at gdcproject dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 May 2022 09:44:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105544 --- Comment #9 from Fabian Vogt --- (In reply to ibuclaw from comment #8) > (In reply to Fabian Vogt from comment #6) > > I had a quick debugging session: The DMD lexer code doesn't really care > > about the size of the buffer and instead runs until it encounters eithe= r a 0 > > or 0x1A byte. The stdin read loop in d_parse_file doesn't explicitly > > 0-terminate the buffer, which means that it works randomly... > >=20 >=20 > OK, so the suggestion would be to zero the padding at the end of the input > buffer then. > > --- a/gcc/d/d-lang.cc > +++ b/gcc/d/d-lang.cc > @@ -1072,6 +1072,10 @@ d_parse_file (void) > global.params.doHdrGeneration); > modules.push (m); >=20=20 > + /* Zero the padding past the end of the buffer so the D lexer has a > + sentinel. The lexer only reads up to 4 bytes at a time. */ > + memset (buffer + len, '\0', 16); > + > /* Overwrite the source file for the module, the one created by > Module::create would have a forced a `.d' suffix. */ > m->src.length =3D len; Yep, that should work. Though I wonder why 16B of padding and not just a si= ngle byte for the 0. FWICT the lexer reads a single byte at a time only (utf8_t = is an unsigned char), so it should stop at the first 0. The comment above explaining the padding mentions a "final '\n'" which shou= ld probably be adjusted with the change to \0.=