From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/15042 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] ftello: Need adjust file offset before switching to write Date: Wed, 18 Dec 2019 08:46:36 -0500 Message-ID: <20191218134636.GM1666@brightrain.aerifal.cx> References: <07082d7e15024b06ba261fbb4e29eac5@huawei.com> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="80834"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) Cc: "musl@lists.openwall.com" , "Songyunlong (Euler)" To: "wangjianjian (C)" Original-X-From: musl-return-15058-gllmg-musl=m.gmane.org@lists.openwall.com Wed Dec 18 14:49:17 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1ihZhU-000KwJ-K5 for gllmg-musl@m.gmane.org; Wed, 18 Dec 2019 14:49:16 +0100 Original-Received: (qmail 24490 invoked by uid 550); 18 Dec 2019 13:49:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 24472 invoked from network); 18 Dec 2019 13:49:13 -0000 Content-Disposition: inline In-Reply-To: <07082d7e15024b06ba261fbb4e29eac5@huawei.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:15042 Archived-At: On Wed, Dec 18, 2019 at 10:18:16AM +0000, wangjianjian (C) wrote: > Consider below code flow: > > FILE *fp = fopen("foobar", "w+"); > fputs("hello", fp); > rewind(fp); > fgetc(fp); > ungetc('x', fp); > fputs("world", fp); ^^^^^^^^^^^^^^^^^^^ This line produces UB. You can't perform a write after ungetc without an intervening successful seek (or hitting EOF). Rich