Bug 241309 - huge empty file created after an ungetwc() followed by fwide()
Summary: huge empty file created after an ungetwc() followed by fwide()
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: glibc   
(Show other bugs)
Version: 4.4
Hardware: All
OS: Linux
Target Milestone: ---
: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2007-05-24 23:50 UTC by Martin Sebor
Modified: 2016-11-24 15:20 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2007-05-30 14:31:40 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Output of strace ./a.out >/dev/null 2>/dev/pts/1 (4.96 KB, text/plain)
2007-05-24 23:50 UTC, Martin Sebor
no flags Details

Description Martin Sebor 2007-05-24 23:50:55 UTC
We're seeing the following unusual behavior of the program below on Red Hat
Advanced Server 4, Update 4:

$ cat t.c && gcc t.c && rm -f foo.out && ./a.out > foo.out && ls -l foo.out &&
du -k foo.out
#include <stdio.h>
#include <wchar.h>

int main ()
    puts ("");
    ungetwc ('A', stdout);
    fwide (stdout, 0);
    return 0;
-rw-r--r--  1 sebor devel 182888783729 May 24 16:44 foo.out
16      foo.out

The output of strace on the program is in the attached file.

Here's info on libc:

$ ldd a.out && /lib64/tls/libc.so.6
        libc.so.6 => /lib64/tls/libc.so.6 (0x000000381b500000)
        /lib64/ld-linux-x86-64.so.2 (0x000000381b100000)
GNU C Library stable release version 2.3.4, by Roland McGrath et al.
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
Compiled by GNU CC version 3.4.6 20060404 (Red Hat 3.4.6-2).
Compiled on a Linux 2.4.20 system on 2006-07-04.
Available extensions:
        GNU libio by Per Bothner
        crypt add-on version 2.1 by Michael Glad and others
        Native POSIX Threads Library by Ulrich Drepper et al
        RT using linux kernel aio
        The C stubs add-on version 2.1.2.
        GNU Libidn by Simon Josefsson
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
Thread-local storage support included.
For bug reporting instructions, please see:

Comment 1 Martin Sebor 2007-05-24 23:50:55 UTC
Created attachment 155405 [details]
Output of strace ./a.out >/dev/null 2>/dev/pts/1

Comment 2 Jakub Jelinek 2007-05-25 06:37:01 UTC
This testcase violates ISO C99, 7.19.2(5):
"wide character input/output functions shall not be applied to a byte-oriented
puts is a byte output function, therefore the stream after puts is byte-oriented.
ungetwc is wide input/output function and thus must not be used until you
reorient the stream.

Comment 3 Martin Sebor 2007-05-25 20:52:42 UTC
I suspected the program was invalid but didn't look carefully enough for
where the standard says so. Thanks for taking the time to provide the

Even though the program is not valid I thought you might like to know
about this type of behavior and consider making a change. I note that
Enterprise Linux 5 creates a file of 0 size so it looks like the change
may have already been implemented.

Comment 4 Jakub Jelinek 2007-05-30 14:31:40 UTC
Why should we slow all correctly built programs to accomodate an invalid program?

Note You need to log in before you can comment on or make changes to this bug.