[comp.lang.c] Does anyone know why this is crashing??

robert@triton.jpl.nasa.gov (Robert Angelino) (06/01/91)

I have this bit of code that works perfectly on a SPARC and crashes
on a VMS (O/S- V5.3-A) system?!

int
init_files(startup_file,...)
	char *startup_file;
{
char buf[256];

#define EOPEN "Unable to open %s file \"%s\"\n"
(void) print_msg(PERROR,"init_files()",
                 sprintf(buf,EOPEN,"startup",startup_file));

	.
	.
	.
	.
	.
	.
}

main()
{
char buf[256];

(void) strcpy(buf,"tc_startup.dat");
(void) init_files(buf,...);

}

It's crashing when it hits the sprintf call in init_files().
I have the following logicals set in the build env
(LNM$PROCESS_TABLE)

  "LNK$LIBRARY" = "SYS$LIBRARY:VAXCCURSE"
  "LNK$LIBRARY_1" = "SYS$LIBRARY:VAXCRTL"


any and all help/suggestions are welcome and will prevent further 
hair lose.

thanks in advance
-- 
    -     ------       -                              Robert Angelino
   | |   | ----  \    | |                             ms T-1704L
   | |   | |   \ |    | |                             4800 Oak Grove Drive
   | |   | | --  |    | |                             Pasadena, CA 91109
---| |   | | \__/     | |___                          robert@triton.jpl.nasa.gov
\____|et |_|ropulsion |_____\aboratory                (818) 354-9574

fenn@wpi.WPI.EDU (Brian Fennell) (06/01/91)

In article <6240@mahendo.Jpl.Nasa.Gov> robert@triton.JPL.NASA.GOV writes:
>I have this bit of code that works perfectly on a SPARC and crashes
>on a VMS (O/S- V5.3-A) system?!
>
>int
>init_files(startup_file,...)
>	char *startup_file;
>{
>char buf[256];
>
>#define EOPEN "Unable to open %s file \"%s\"\n"
>(void) print_msg(PERROR,"init_files()",
>                 sprintf(buf,EOPEN,"startup",startup_file));
>
>    -     ------       -                              Robert Angelino

all sprintf's were not created equal (Thanks to the ANSI non-standard
standard)  try changing:
	sprintf(buf, ...... ) 
to
	(sprintf(buf,.....) , buf)

Brian Fennell == fenn@wpi.wpi.edu 

mouse@thunder.mcrcim.mcgill.edu (der Mouse) (06/06/91)

In article <6240@mahendo.Jpl.Nasa.Gov>, robert@triton.jpl.nasa.gov (Robert Angelino) writes:

> I have this bit of code that works perfectly on a SPARC and crashes
> on a VMS (O/S- V5.3-A) system?!

> #define EOPEN "Unable to open %s file \"%s\"\n"
> (void) print_msg(PERROR,"init_files()",
>                  sprintf(buf,EOPEN,"startup",startup_file));

> It's crashing when it hits the sprintf call in init_files().

Are you sure?  I suspect it's crashing inside print_msg.

sprintf() returns the resulting string on some, but not all, systems.
Not having access to a VMS machine to try this out on, I suspect
sprintf() there is returning something else - zero, or the number of
characters written, or some such.  Try instead

   sprintf(buf,EOPEN,"startup",startup_file);
   (void) print_msg(PERROR,"init_files()",buf);

which should work everywhere.

If that doesn't fix it I have no more ideas and would have to plunge in
with a debugger.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu

boyd@prl.dec.com (Boyd Roberts) (06/06/91)

 In article <6240@mahendo.Jpl.Nasa.Gov>, robert@triton.jpl.nasa.gov (Robert Angelino) writes:
 
> I have this bit of code that works perfectly on a SPARC and crashes
> on a VMS (O/S- V5.3-A) system?!
> 
> #define EOPEN "Unable to open %s file \"%s\"\n"
> (void) print_msg(PERROR,"init_files()",
>                  sprintf(buf,EOPEN,"startup",startup_file));
> 

Sounds like you've forgotten that sprintf(3) returns `char *' on some systems
and `int' on others.  What's the bet that the VMS sprintf(3) returns `int'?

Never use sprintf(3)'s return value.  Don't even think about #ifdef'ing
for the two types.  Bite the bullet, and code around it.


Boyd Roberts			boyd@prl.dec.com

``When the going gets wierd, the weird turn pro...''