Xref: utzoo comp.unix.questions:10100 comp.unix.wizards:12159 Path: utzoo!attcan!uunet!husc6!rutgers!att!ulysses!andante!alice!debra From: debra@alice.UUCP (Paul De Bra) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: alloca problem? Keywords: alloca stack 386 sysv Message-ID: <8393@alice.UUCP> Date: 5 Nov 88 18:26:29 GMT References: <17026@santra.UUCP> Reply-To: debra@alice.UUCP () Organization: AT&T, Bell Labs Lines: 42 In article <17026@santra.UUCP> hsu@santra.UUCP (Heikki Suonsivu) writes: ]Why this fails, ] ]huu(name) ] char *name; ]{ ] char *d; ] ] d = strcpy(alloca(strlen(name) + 1), name); ] ] .... ]} ] ]but this works? ] ]huu(name) ] char *name; ]{ ] char *d; ] ] d = alloca(strlen(name) + 1); ] strcpy(d, name); ] ] .... ]} ] This is not a problem of your Unix but of your program. Alloca does some messing around with the stack. When you call it while you are pushing arguments on the stack, you get in trouble. What I think is happening is that name gets pushed on the stack, and then the alloca call moves the stack pointer causing strcpy to go look for "name" in a different place. The second example works because you first modify the stack and then start pushing the arguments on the stack. I am not saying that the first example won't work on any system (that has alloca) but is is bad practice. Paul. -- ------------------------------------------------------ |debra@research.att.com | uunet!research!debra | ------------------------------------------------------