Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!husc6!mit-eddie!apollo!gaz
From: gaz@apollo.COM (Gary Zaidenweber)
Newsgroups: comp.sys.apollo
Subject: Re: How does ios_dir_$open work?
Message-ID: <3def3653.52e@apollo.COM>
Date: 18 Aug 88 16:02:00 GMT
References: <8180@cup.portal.com>
Organization: Apollo Computer, Chelmsford, Mass.
Lines: 44

From article <8180@cup.portal.com>, by Jinfu@cup.portal.com:
> 
> 
> I don't understand why following codes don't work:
> 
> 
> #include 
> #include 
> 
> main(argc, argv)
> int      argc;
> char    *argv;
> {
> char    *str1;
> strcpy(str1, argv[1]);
> }
> 
> The runtime error is 'access violation'. If I change definition of str1
> to array, the code will work:
> 
> char      str1[256];
> 
> 
> Our system is running 9.7 with BSD4.2. Is this my misunderstanding of
> strcpy or just another 'It is fixed in SR10' bug? 
> 
> (after all, isn't it nice to hear this than, say, involling 50 nodes
> in your network? :-)
> 
> Jinfu Chen

Its neither a misunderstanding of strcpy or a "bug fixed in SR10", its 
a C programming error. If you declare str1 to be a pointer to char without
a backing storage of characters declared somewhere else, str1 is an 
uninitialized pointer. Depending on the C implementation, it may be
NULL or point into hyperspace. When you declare it as an array, it then
can be used as either a pointer to the backing storage of the array or
as the array itself. Note also, please that your typed-in example needs
to declare argv as "char *argv[]" in order to work.

-- 
    UUCP:   ...{umix,mit-eddie,uw-beaver}!apollo!gaz
    ARPA:   gaz@apollo.COM
    AT&T:   (508)256-6600 x6081
    Its never too late to have a happy childhood!