Possible Bug in BSD

madd at bucsb.bu.edu.UUCP madd at bucsb.bu.edu.UUCP
Fri Feb 27 13:22:46 AEST 1987


In article <4685 at brl-adm.ARPA> sefunix%sefe.decnet at nwc-143b.arpa (SEFE::SEFUNIX) writes:
>We have run into a little problem on both Ultrix-32m (DEC microvax)
>and MT. Xinu 4.3BSD on a DEC microvax. Can someone try this program
>on their system and see if they also get a segmentation violation
>on the fopen of argv[1]. 
>
>And if so, why?
>
>#include <stdio.h>
>
>struct abc
>{
>	short Red;
>	short Green;
>	short Blue;
>	short Alpha;
>};
>
>main (argc, argv)
>int argc; 
 vvvvvvvvvvvv
>char **argv;
 ^^^^^^^^^^^^
>{
>	FILE *f1, *fopen();
>
>	struct abc point[151][451];
>
>	if (argc !=2)
>	{
>	   puts("\n Usage: InputFileName \n");
>	   exit(1);
>	}
>
>	if((f1 = fopen(argv[1], "r")) == NULL )
>	{
>	   printf("I can't open %s\n", argv[1]);
>	   exit(1);
>	}
>
>	fclose(f1);
>}

You really shouldn't have declared char **argv if you want to treat
argv as an array.  Instead, change that declaration to *argv[], or
reference it as a pointer structure (eg *(argv+1)==argv[1]).  I
suspect that C doesn't treat arrays of pointers exactly as it treats
pointers to pointers, but I'm not really that sharp on the subject.  I
just treat them as if they were two completely different types of
variables, and this keeps things simple.  Some C compilers will give
you "type mismatch" errors when you define a pointer value and then
reference it as an array.  The 4.3BSD compiler on our vax 750 did not,
however.

jim frost
madd at bucsf.bu.edu
..!harvard!bu-cs!bucsf!madd



More information about the Comp.unix.wizards mailing list