Re: Is this OK in C++ and C?
Zbigniew Komarnicki <cblasius@gmail.com> writes:
>
> I wanted to prohibit user to assign negative value to a variable.
> This variable is later passed to a recurrence function as
> argument and of course I got segmentation fault, because
> the function is called 4294967291 times.
>
You MUST check the input. Consider a user who has an int with the
value he wants to pass. If there were a check, he'd just write:
func(unsigned int(x)) to get the thing to compile.
Or a user who in error computes a silly large positive value by any nunmber of
means.
There are languages which attempt to do bounds checking statically,
but C isn't like that - which is why buffer overflow still is the
friend of the malware writer.
Reply to: