Re: What is the reason for Perl?
- From: "Eric J. Roode" <sdn.girths00869@xxxxxxxxxxx>
- Date: Mon, 12 Dec 2005 16:48:25 -0600
John Bokma <john@xxxxxxxxxxxxxxx> wrote in
news:Xns972AA09354FA1castleamber@xxxxxxxxxxx:
> "Eric J. Roode" <sdn.girths00869@xxxxxxxxxxx> wrote:
>
>> For example: You're writing a library function, which writes to a
>> buffer provided by the caller. The caller will typically allocate a
>> string (say), either on the stack or dynamically via malloc, and pass
>> it to your function. Wouldn't it be nice if your function could
>> determine how large the buffer was,
>
> If it's a string, you could check for \0 now couldn't you? And if you
> want to use something else, what's the problem of wrapping it all nice
> into a library?
char buf[80];
strcpy (buf, "hello");
After this call, buf[5] is '\0'. Before that call, all of the elements of
buf are uninitialized; possibly they're all '\0', possibly they're all
random garbage.
Checking for '\0' tells you how long the string is (5 characters), but
doesn't tell you how long the allocated buffer is (80 bytes).
char buf[4];
strcpy (buf, "hello");
strcpy() can't tell that you're trying to stuff too much data into the
buffer. There simply is no way.
--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
.
- Follow-Ups:
- Re: What is the reason for Perl?
- From: John Bokma
- Re: What is the reason for Perl?
- References:
- What is the reason for Perl?
- From: robic0
- Re: What is the reason for Perl?
- From: Eric J. Roode
- Re: What is the reason for Perl?
- From: John Bokma
- Re: What is the reason for Perl?
- From: Eric J. Roode
- Re: What is the reason for Perl?
- From: John Bokma
- What is the reason for Perl?
- Prev by Date: Can one use local to temporarily close STDERR?
- Next by Date: Re: What is the reason for Perl?
- Previous by thread: Re: What is the reason for Perl?
- Next by thread: Re: What is the reason for Perl?
- Index(es):
Relevant Pages
|
|