|
|
Message-ID: <20191218134636.GM1666@brightrain.aerifal.cx>
Date: Wed, 18 Dec 2019 08:46:36 -0500
From: Rich Felker <dalias@...c.org>
To: "wangjianjian (C)" <wangjianjian3@...wei.com>
Cc: "musl@...ts.openwall.com" <musl@...ts.openwall.com>,
"Songyunlong (Euler)" <yunlong.song@...wei.com>
Subject: Re: [PATCH] ftello: Need adjust file offset before switching
to write
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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.