From: Steve Graegert <graegerts@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: Help: need to prevent infinite loop
Date: Wed, 18 Jan 2006 17:33:56 +0100 [thread overview]
Message-ID: <6a00c8d50601180833l138ec402xc5dfd121277aad8@mail.gmail.com> (raw)
In-Reply-To: <200601182154.36474.samjnaa@gmail.com>
On 1/18/06, Shriramana Sharma <samjnaa@gmail.com> wrote:
> Tuesday, 17 January 2006 12:44 samaye, Jesse Ruffin alekhiit:
>
> > This inelegant, but satisfactory, method fixes the problem:
> > fgets(buf,12,stdin);
>
> Thanks for your reply and sorry for the delay in mine.
>
> The suggestion to use fgets reminded me of this gcc-generated warning with
> gets:
>
> samjnaa@linux:~/bin/learning> gcc -Wall -o gets gets.c
> /tmp/ccA8bxgm.o: In function `main':
> gets.c:(.text+0x25): warning: the `gets' function is dangerous and should not
> be used.
>
> Though I did not get such a warning with fgets, I wonder why this function is
> considered dangerous. Could the same problem perhaps apply to fgets too and
> gcc doesn't inform me of it?
Shriramana,
As fgets(3), gets(3) reads into a buffer, but no check for buffer
overrun is performed, which can result in serious bugs. fgets(3) takes
the buffer size as the second argument and no more characters than
specified are written into the buffer.
\Steve
--
Steve Graegert <graegerts@gmail.com>
Software Consultant {C/C++ && Java && .NET}
Office: +49 9131 7123988
Mobile: +49 1520 9289212
next prev parent reply other threads:[~2006-01-18 16:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-17 4:36 Help: need to prevent infinite loop Shriramana Sharma
2006-01-17 7:14 ` Jesse Ruffin
2006-01-18 16:24 ` Shriramana Sharma
2006-01-18 16:33 ` Steve Graegert [this message]
2006-01-22 10:20 ` Glynn Clements
2006-01-22 11:28 ` Jesse Ruffin
2006-01-23 5:57 ` Jesse Ruffin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6a00c8d50601180833l138ec402xc5dfd121277aad8@mail.gmail.com \
--to=graegerts@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).