Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcvax!mhres!jv From: jv@mhres.mh.nl (Johan Vromans) Newsgroups: comp.lang.c Subject: Re: Allocation for pointers Message-ID: <1272@mhres.mh.nl> Date: Fri, 4-Sep-87 17:05:13 EDT Article-I.D.: mhres.1272 Posted: Fri Sep 4 17:05:13 1987 Date-Received: Sun, 6-Sep-87 02:08:26 EDT References: <1357@faline.bellcore.com> Reply-To: jv@mhres.mh.nl (Johan Vromans) Organization: Multihouse N.V., The Netherlands Lines: 34 In article <1357@faline.bellcore.com> gtchen@faline.UUCP (George T. Chen) writes: >I have a question about the following program: > >main() { char *a; a = "text"; recurs(a);} > >void recurs(a) >char *a; >{ strcat(a,"more text"); > if (some conditional test) recurs(a); >} > >As I understand it, I'm passing the address of the variable a into >the routine recurs. At no point do I specify how large of a buffer >a will eventually point to. Is there a limit and is it compiler >dependent? Your pointer is pointing in your program space. The "strcat" is therefore overwriting your program. Depending on how the compiler/linker have arranged your program and data, disaster will result pretty soon. The precise result is implementation dependent. Imagine the original text being placed on the stack ... -- Johan Vromans | jv@mh.nl via European backbone Multihouse N.V., Gouda, the Netherlands | uucp: ..{?????!}mcvax!mh.nl!jv "It is better to light a candle than to curse the darkness" -- Johan Vromans | jv@mh.nl via European backbone Multihouse N.V., Gouda, the Netherlands | uucp: ..{?????!}mcvax!mh.nl!jv "It is better to light a candle than to curse the darkness"