Return to BSD News archive
Xref: sserve comp.os.386bsd.questions:11993 comp.os.386bsd.development:2363 comp.os.386bsd.misc:2983 Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msuinfo!agate!howland.reston.ans.net!gatech!swrinde!news.uh.edu!uuneo.neosoft.com!Starbase.NeoSoft.COM!nobody From: peter@Starbase.NeoSoft.COM (Peter da Silva) Newsgroups: comp.os.386bsd.questions,comp.os.386bsd.development,comp.os.386bsd.misc Subject: Re: Why does FreeBSD 1.1.5 say gets() is unsafe? Date: 1 Aug 1994 09:37:27 -0500 Organization: NeoSoft Internet Services +1 713 684 5969 Lines: 32 Message-ID: <31j1b7$jgp@Starbase.NeoSoft.COM> References: <30lrf3$2ii@acmez.gatech.edu> <31f1v8$2lg@mozo.cc.purdue.edu> <31gvf1$h19@starbase.neosoft.com> <31h4u7$9os@kralizec.zeta.org.au> NNTP-Posting-Host: starbase.neosoft.com In article <31h4u7$9os@kralizec.zeta.org.au>, Bruce Evans <bde@kralizec.zeta.org.au> wrote: >The NULL pointer references are safer if they cause a core dump. Now long >lines are silently split. But NULL pointer references *don't* cause a core dump. NULL pointer references have an undefined effect. In fact in the same program on some platforms they may have different effects at different times. On some platforms they *do* core dump, and that's good. On others, well, I've seen some pretty bizzarre behaviour from old versions of awk. I'd rather a failure mode that was consistent across platforms. It makes porting so much easier. You feel like getting into an infinite regress redefining a hypothetical application? The best solution is to restructure the code so it doesn't use fixed size buffers at all, and if possible doesn't even need to read a whole line at a time. int c; while(!feof(stdin) && (c = getchar()) != EOF) { switch(c) { case '\n': complete_line(); break; case ' ': complete_word(); break; } } But you're right, the inner if() in my example should have some sort of failure indication.