In message <87oetz6gjo.fsf / serein.a02.aist.go.jp> on Tue, 23 Dec 2003 18:15:46 +0900, Tanaka Akira <akr / m17n.org> wrote: > In article <200312230824.hBN8O5kM005374 / sharui.nakada.kanuma.tochigi.jp>, > nobu.nakada / nifty.ne.jp writes: > > > 私のところではcoreは吐きませんでしたが、巨大なファイルができま > > した。単にglibcのバグなのか、それともreadせずにungetc()すること > > 自体がそもそも未定義動作なのか。 同プログラムはNetBSD current上では、 taca@edge[100]:./ungetctest 120 taca@edge[101]:ls -l zz -rw-r--r-- 1 taca wheel 1 Dec 24 01:11 zz となりました。 > たしか C の仕様としては保証されていなかったように思います。 どうなんでしょうね。ざっと、そこいらの ungetc(3) を見ると明らかなのは、 One character of push-back is guaranteed. というあたりは確実なようです。もうちょっと探すと"ANSI C Rationale"とい う正式な標準ではないもの(<http://www.lysator.liu.se/c/rat/title.html>) がありました。その4.9.7.11 The ungetc functionの冒頭には、 The Base Document requires that at least one character be read before ungetc is called, in certain implementation-specific cases. The Committee has removed this requirement, thus obliging a FILE structure to have room to store one character of pushback regardless of the state of the buffer; it felt that this degree of generality makes clearer the ways in which the function may be used. とありました。 > したがって、Ruby としては、そういう危ないのをユーザに指示されたからと > いって呼んでいいのか、というところが問題なわけです。 危ないのは「readせずにungetc(3)」ではなく、そこにバグを持つ実装が存在 するということになりそうです。 -- 神戸 隆博 / Takahiro Kambe