Re: how can we check to not enter the any string or char?
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Thu, 01 Nov 2007 18:47:47 -0500
Flash Gordon wrote:
CBFalconer wrote, On 01/11/07 16:12:.... snip ...
if (((UINT_MAX - ch) / 10) > value) {
This is meant to be a bounded input, pass in and test against the bounds
allowed rather than some other value.
No, this is intended to ensure the value fits into an unsigned int.
.... snip ...
/* overflow detected, decide what to do */
ch = ch + '0'; /* restore char value */
break;
}
value = 10 * value + ch;
}
ungetc(ch, f); /* keep exit char for the user */
return err;
} /* untested - you check it out */
Still untested by me.
Of course, you have just done most of this chaps homework.
No I haven't. The function is incomplete. Nobody seems to notice
that it doesn't bother to return value, as it should, and that err
should be a further parameter (*err). What I have done is
encourage him to develop a standard reusable input mechanism, whose
value can be checked by the caller, and which doesn't require
(possibly) long strings etc.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
.
- Follow-Ups:
- Re: how can we check to not enter the any string or char?
- From: Charlie Gordon
- Re: how can we check to not enter the any string or char?
- From: Flash Gordon
- Re: how can we check to not enter the any string or char?
- References:
- Re: how can we check to not enter the any string or char?
- From: andreyvul
- Re: how can we check to not enter the any string or char?
- From: Jack Klein
- Re: how can we check to not enter the any string or char?
- From: Philip Potter
- Re: how can we check to not enter the any string or char?
- From: santosh
- Re: how can we check to not enter the any string or char?
- From: emre esirik(hacettepe computer science and engineering)
- Re: how can we check to not enter the any string or char?
- From: CBFalconer
- Re: how can we check to not enter the any string or char?
- From: Flash Gordon
- Re: how can we check to not enter the any string or char?
- Prev by Date: Re: Simple allocation of two buffer on AMD64
- Next by Date: Re: A Trend Towards Lower Software Maintenance Budgets?
- Previous by thread: Re: how can we check to not enter the any string or char?
- Next by thread: Re: how can we check to not enter the any string or char?
- Index(es):
Relevant Pages
|