Re: Comparing string input to enum data type
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 28 Feb 2007 11:32:55 -0800
"Bill Pursell" <bill.pursell@xxxxxxxxx> writes:
On Feb 27, 10:17 pm, Keith Thompson <k...@xxxxxxx> wrote:
"Bill Pursell" <bill.purs...@xxxxxxxxx> writes:
if( 0 == strncmp("red", a, sizeof "red") )
c = red;
else if ...
Why not just strcmp("red", a)?
Just a general tendency to refrain from using
strcmp. In this case, since one of the strings is
fixed, there's no security issue with strcmp (until
the code maintainer modifies the code...),
but I believe it's a good habit to use the strncmp
variant.
strcmp() is a security problem only if one of the arguments isn't a
null-terminated string. I'd be more afraid of getting the strncmp()
arguments wrong than of passing bad values to strcmp().
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: Comparing string input to enum data type
- From: Yevgen Muntyan
- Re: Comparing string input to enum data type
- References:
- Comparing string input to enum data type
- From: dtschoepe@xxxxxxxxx
- Re: Comparing string input to enum data type
- From: Bill Pursell
- Re: Comparing string input to enum data type
- From: Keith Thompson
- Re: Comparing string input to enum data type
- From: Bill Pursell
- Comparing string input to enum data type
- Prev by Date: Re: pointer initialization
- Next by Date: Re: Polyspace Problem
- Previous by thread: Re: Comparing string input to enum data type
- Next by thread: Re: Comparing string input to enum data type
- Index(es):
Relevant Pages
|