system() --- the C function from hell?

James C. Benz jcbst3 at cisunx.UUCP
Wed May 3 01:42:15 AEST 1989


In article <1827 at uop.edu> jeff at uop.edu (Jeff Ferguson) writes:
>
>	Hi kids,
>
>	The system() call seems to wreak havoc with integer variables.
>I have the following code:
>
>/****** Code *******/
>
>int lowp, hip;
>...
>scanf("%d", &hip);
>scanf("%d", &lowp);
>sprintf(str, "/bin/mkdir directory");
>system(str);
>...
>
>/**** End Of Code ****/
>
>I printed the values of LOWP and HIP before the system() call, and
>everthing was pee-chee (like the folder).  I print them out after
>the call and the values have been blown to high Heaven: before they
>were both 3, while after system(str) they are in the tens of millions.
>
>OK, people, for $200 and the chance at the Chevy Sprint Turbo --- my
>question is this: what is happenning here an how can it be fixed?  I
>am stymied.

You don't mention how you declare the variable str, so I can't be sure at this,
but for a Sprint Turbo----

My experience with zapped int variables has nothing to do with the system call,
but rather with the length of string variables being declared too short to hold
what you try to stuff into them.  Are you sure the str size is long enough to
hold what you sprintf into it?  Is str declared directly before the two ints?
Sprintf and other string routines in (ATT Sys V) standard C don't know how long
the declared length of a string is, and will quite happily zap whatever is in
their way.  Also, I wouldn't trust scanf for anything.  So where can I pick up
the keys?
Newsgroups: comp.unix.questions,comp.unix.wizards
Subject: Re: system() --- the C function from hell?
Summary: 
Expires: 
References: <1827 at uop.edu>
Sender: 
Reply-To: jcbst3 at unix.cis.pittsburgh.edu (James C. Benz)
Followup-To: 
Distribution: 
Organization: Univ. of Pittsburgh, Comp & Info Sys
Keywords: system, unix, question, does anyone use this line?

In article <1827 at uop.edu> jeff at uop.edu (Jeff Ferguson) writes:
>
>	Hi kids,
>
>	The system() call seems to wreak havoc with integer variables.
>I have the following code:
>
>/****** Code *******/
>
>int lowp, hip;
>...
>scanf("%d", &hip);
>scanf("%d", &lowp);
>sprintf(str, "/bin/mkdir directory");
>system(str);
>...
>
>/**** End Of Code ****/
>
>I printed the values of LOWP and HIP before the system() call, and
>everthing was pee-chee (like the folder).  I print them out after
>the call and the values have been blown to high Heaven: before they
>were both 3, while after system(str) they are in the tens of millions.
>
>OK, people, for $200 and the chance at the Chevy Sprint Turbo --- my
>question is this: what is happenning here an how can it be fixed?  I
>am stymied.

You don't mention how you declare the variable str, so I can't be sure at this,
but for a Sprint Turbo---- AND $200 (I'll settle for the bucks)

My experience with zapped int variables has nothing to do with the system call,
but rather with the length of string variables being declared too short to hold
what you try to stuff into them.  Are you sure the str size is long enough to
hold what you sprintf into it?  Is str declared directly before the two ints?
Sprintf and other string routines in (ATT Sys V) standard C don't know how long
the declared length of a string is, and will quite happily zap whatever is in
their way.  Also, I wouldn't trust scanf for anything.  So where can I pick up
the keys?











line fodder












and more line fodder
-- 
Jim Benz 		     jcbst3 at unix.cis.pittsburgh.edu     If a modem 
University of Pittsburgh					 answers,
UCIR			     (412) 648-5930			 hang up!



More information about the Comp.unix.questions mailing list