Re: Difference between strcpy() and strcat()?
From: Pascal Damian (pascaldamian_at_icqmail.com)
Date: 03/05/04
- Next message: Michael Borgwardt: "Re: OFF-TOPIC:: Why Lisp is not my favorite programming language"
- Previous message: Ray Dillinger: "Re: OFF-TOPIC:: Why Lisp is not my favorite programming language"
- In reply to: Leor Zolman: "Re: Difference between strcpy() and strcat()?"
- Next in thread: Jens.Toerring_at_physik.fu-berlin.de: "Re: Difference between strcpy() and strcat()?"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Difference between strcpy() and strcat()?"
- Reply: Leor Zolman: "Re: Difference between strcpy() and strcat()?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Mar 2004 04:18:39 -0800
Leor Zolman <leor@bdsoft.com> wrote in message news:> "strcpy is safer than strcat because it is easier to check programmatically
> that a strcpy operation will not overflow the buffer: presumably you know
> the length of your destination buffer, so all you have to do is check the
> length of the source string. With strcat, on the other hand, you have to
> test the length of the existing string in the buffer, add the length of the
> string to be appended, and make sure the total resulting length is going to
> fit into your available space."
>
> But that would actually be rubbish...I've probably had more overruns with
> functions like strcpy than with strcat. Why? Because I've been more
> /careful/ while using strcat... ;-)
To Jens,
Yes, sorry. The question should be: "what's the difference between
using strcat() or strcpy() to append a string?"
To Leor,
Here's exactly where I read it, from a post at comp.lang.ruby:
======================== start quote ============================
> p = (char *)getenv("LD_LIBRARY_PATH");
>> if ((env = (char *)malloc(512+1+(p==NULL ? 0:strlen(p)))) ==
NULL) {
>> fprintf(stderr, "malloc() failed: %s\n", strerror(errno));
>> exit(1);
>> }
>> strcat(env, "LD_LIBRARY_PATH=");
Use strcpy instead of strcat here, content of malloc'ed area is
not guaranteed.
======================== end quote ============================
URL: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=200403041635.i24GZh4Y030395%40sharui.nakada.niregi.kanuma.tochigi.jp
URL: http://tinyurl.com/393yz
Now what does the poster mean by "content of malloc'ed area is not
guaranteed"?
-- Pascal
- Next message: Michael Borgwardt: "Re: OFF-TOPIC:: Why Lisp is not my favorite programming language"
- Previous message: Ray Dillinger: "Re: OFF-TOPIC:: Why Lisp is not my favorite programming language"
- In reply to: Leor Zolman: "Re: Difference between strcpy() and strcat()?"
- Next in thread: Jens.Toerring_at_physik.fu-berlin.de: "Re: Difference between strcpy() and strcat()?"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Difference between strcpy() and strcat()?"
- Reply: Leor Zolman: "Re: Difference between strcpy() and strcat()?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|