strcpy HELP!!!!

1998-04-17 Thread Phil
I'm using libc6 2.0.7pre1-4 and strcpy gives me a segmentation
error!
I've attached my C test program for inspection(source only).

I only do a few things.  malloc memory for a variable(forgot a
corresponding free)
copy a string in this varible, copy this string to another
string, print both
on the screen.  The exact error message is attached to the
source.

I will now check bug track.

Thanks in advance 

Philip

-- 
  _ 
 _ \ \   From Witomatic Keep, 
   / \_\ |   Home of Witwerg the Sage
  |  //o_/ | -- 
| \ \_/  Weilding GCC and Linux 2.0.33
 \ \_Tschuss!  Auf Wiedsehen!#include stdlib.h
#include stdio.h
#include string.h

void main(void)
{
char *temp1, *temp2;
temp1 = malloc (10);
strcpy (temp1, high all);
strcpy (temp2, temp1);
printf(%s %s, temp1, temp2);
}
/* error --- program recieved signal SIGSEGV, Segmentation Fault.
 * 0x40050be7*/


Re: strcpy HELP!!!!

1998-04-17 Thread Ben Pfaff
This is your fault.  You need to allocate memory for temp2.

   void main(void)
   {
   char *temp1, *temp2;
   temp1 = malloc (10);
insert `temp2 = malloc (10);' here.
   strcpy (temp1, high all);
   strcpy (temp2, temp1);
   printf(%s %s, temp1, temp2);
   }


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]


Re: strcpy HELP!!!!

1998-04-17 Thread aqy6633
 #include stdlib.h
 #include stdio.h
 #include string.h
 
 void main(void)
 {
 char *temp1, *temp2;
 temp1 = malloc (10);
 strcpy (temp1, high all);
 strcpy (temp2, temp1);
 printf(%s %s, temp1, temp2);
 }
 /* error --- program recieved signal SIGSEGV, Segmentation Fault.
  * 0x40050be7*/

No wonder. You have to allocate memory for temp2 string before copying to it.
do temp2=malloc(strlen(temp1)+1); in between of two strcpy and everything's
gonna be OK.

Good luck.

Alex Y.
   _ 
 _( )_
( (o___   +---+
 |  _ 7   |Alexander Yukhimets|
  \()|   http://pages.nyu.edu/~aqy6633/  |
  / \ \   +---+


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]


RE: strcpy HELP!!!!

1998-04-17 Thread Scott D. Killen
Phil,

You are copying the string to temp2 which has not been initialized and is a
NULL pointer.  You need to allocate memory of at least the same size as
temp1 to temp2 and
this will solve your problem.

Scott D. Killen
Scott Killen Software
http://www.skillsoft.com

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Phil
Sent: Wednesday, April 15, 1998 9:01 PM
To: debian-user@lists.debian.org
Subject: strcpy HELP


I'm using libc6 2.0.7pre1-4 and strcpy gives me a segmentation
error!
I've attached my C test program for inspection(source only).

I only do a few things.  malloc memory for a variable(forgot a
corresponding free)
copy a string in this varible, copy this string to another
string, print both
on the screen.  The exact error message is attached to the
source.

I will now check bug track.

Thanks in advance

Philip

--
  _
 _ \ \   From Witomatic Keep,
   / \_\ |   Home of Witwerg the Sage
  |  //o_/ | --
| \ \_/  Weilding GCC and Linux 2.0.33
 \ \_Tschuss!  Auf Wiedsehen!


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]


RE: strcpy HELP!!!

1998-04-17 Thread Lee Brinton

Scott D. Killen writes:
 You are copying the string to temp2 which has not been initialized and is a
 NULL pointer.  You need to allocate memory of at least the same size as
 temp1 to temp2 and
 this will solve your problem.

When using C library string functions always allocate memory of at least the
length of the string pointed to by temp1 plus 1 byte to hold the string
termination character '\0'.

As in:

temp2 = (char*)malloc(strlen(temp1) + 1);

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Lee Brinton | [EMAIL PROTECTED]
PGP public key @ http://www.icubed.com/~6xtippet/pgp-public-key.asc
---
The objective is not to die for your country,
but to make the enemy die for his country.
-- Gen. George Patton
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]


RE: strcpy HELP!!!

1998-04-17 Thread Scott D. Killen
-BEGIN PGP SIGNED MESSAGE-

You are correct.  I was making specific assumptions based on the code
snippet
shown.

- -Original Message-
From: Lee Brinton [mailto:[EMAIL PROTECTED]
Sent: Friday, April 17, 1998 12:40 AM
To: debian-user Mailing List
Subject: RE: strcpy HELP!!!



Scott D. Killen writes:
 You are copying the string to temp2 which has not been initialized and is
a
 NULL pointer.  You need to allocate memory of at least the same size as
 temp1 to temp2 and
 this will solve your problem.

When using C library string functions always allocate memory of at least the
length of the string pointed to by temp1 plus 1 byte to hold the string
termination character '\0'.

As in:

temp2 = (char*)malloc(strlen(temp1) + 1);

- --
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Lee Brinton | [EMAIL PROTECTED]
PGP public key @ http://www.icubed.com/~6xtippet/pgp-public-key.asc
- ---
The objective is not to die for your country,
but to make the enemy die for his country.
-- Gen. George Patton
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


- --
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact
[EMAIL PROTECTED]
-BEGIN PGP SIGNATURE-
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQCVAwUBNTbulgrrqzzf5TWxAQEi2QP/Ye3hKW8cutHTZP415zAmxhBTdElHzJjx
e3j0Aq0MJ+gtDFcCNpraNygmoza2kc8s/wFT3k58npNELO63CaPmiFL2HJcQDiqh
BAdXHxN9toPVVrCYNNbRBK8b2gIb05nBOk6JsFzhW+uqtBv/Ha3mBT7kN/ae8/u8
w8werd/ml58=
=rj5a
-END PGP SIGNATURE-


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]


Re: strcpy HELP!!!

1998-04-17 Thread E.L. Meijer \(Eric\)
Lee Brinton:
 Scott D. Killen writes:
  You are copying the string to temp2 which has not been initialized and is
 a
  NULL pointer.  You need to allocate memory of at least the same size as
  temp1 to temp2 and
  this will solve your problem.
 
 When using C library string functions always allocate memory of at least the
 length of the string pointed to by temp1 plus 1 byte to hold the string
 termination character '\0'.
 
 As in:
 
 temp2 = (char*)malloc(strlen(temp1) + 1);

No they don't always.  From the strcpy man page:

   The  strcpy() function copies the string pointed to be src
   (including the terminating `\0' character)  to  the  array
   pointed  to by dest.  The strings may not overlap, and the
   destination string dest must be large  enough  to  receive
   the copy.

You have to allocate the space by yourself.  However, there is strdup:

NAME
   strdup - duplicate a string

SYNOPSIS
   #include string.h

   char *strdup(const char *s);

DESCRIPTION
   The  strdup()  function  returns a pointer to a new string
   which is a duplicate of the string s.  Memory for the  new
   string  is  obtained with malloc(3), and can be freed with
   free(3).

This function actually does the memory allocation for you.  More
information for aspiring C-programmers can be found typing `info libc',
provided you have the glibcdoc package installed (at least, that is
where the info file is kept on a bo system).

Eric Meijer

-- 
 E.L. Meijer ([EMAIL PROTECTED])  | tel. office +31 40 2472189
 Eindhoven Univ. of Technology | tel. lab.   +31 40 2475032
 Lab. for Catalysis and Inorg. Chem. (TAK) | tel. fax+31 40 2455054


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]


Re: strcpy HELP!!!

1998-04-17 Thread Alex Yukhimets
 Scott D. Killen writes:
  You are copying the string to temp2 which has not been initialized and is a
  NULL pointer.  You need to allocate memory of at least the same size as
  temp1 to temp2 and
  this will solve your problem.
 
 When using C library string functions always allocate memory of at least the
 length of the string pointed to by temp1 plus 1 byte to hold the string
 termination character '\0'.
 
 As in:
 
 temp2 = (char*)malloc(strlen(temp1) + 1);

When doing strcpy(temp2,temp1) ???
How could it possibly do that?  It cannot change the value of temp2,
it is passed by value. Please read man strcpy.

Good luck.

Alex Y.
-- 
   _ 
 _( )_
( (o___   +---+
 |  _ 7   |Alexander Yukhimets|
  \()|   http://pages.nyu.edu/~aqy6633/  |
  / \ \   +---+


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]