[Nagiosplug-checkins] CVS: nagiosplug/plugins utils.c,1.7,1.8

Karl DeBisschop kdebisschop at users.sourceforge.net
Sun Oct 20 21:07:03 CEST 2002


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv2209/plugins

Modified Files:
	utils.c 
Log Message:
use asprintf to do strscpy

Index: utils.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** utils.c	18 Oct 2002 04:41:05 -0000	1.7
--- utils.c	21 Oct 2002 04:05:48 -0000	1.8
***************
*** 354,364 ****
  /******************************************************************************
   *
!  * Copies one string to another
!  *
!  * Given a pointer destination string, which may or may not already
!  * hold some text, and a source string with additional text (possibly
!  * NULL or empty), returns a pointer to a a copy of the source
!  * string. Uses realloc to free memory held by the dest argument if
!  * new storage space is required, and any previously existing data in
   * the destination string is lost.
   *
--- 354,358 ----
  /******************************************************************************
   *
!  * Copies one string to another. Any previously existing data in
   * the destination string is lost.
   *
***************
*** 376,390 ****
  
  	if (src == NULL)
! 		return dest;
! 
! 	len = strlen (src) + 1;
! 	if (dest == NULL)
! 		dest = malloc (len);
! 	else if (strlen (dest) < len)
! 		dest = realloc (dest, len);
! 	if (dest == NULL)
! 		terminate (STATE_UNKNOWN, "failed realloc in strscpy\n");
  
! 	strncpy (dest, src, len);
  
  	return dest;
--- 370,376 ----
  
  	if (src == NULL)
! 		return NULL;
  
! 	asprintf (&dest, "%s", src);
  
  	return dest;





More information about the Commits mailing list