mirror of
				https://github.com/osmarks/ngircd.git
				synced 2025-11-04 07:52:59 +00:00 
			
		
		
		
	Updated to latest strl{cat|cpy} code of rsync:
- Make sure that strlcpy() returns the right value when the bufsize is 0. - Fixed a bug in strlcat() where it would not properly detect a no-change condition if called with an initial string longer than the specified size limit (due to an unsigned var's inability to go negative). Patch by Florian Westphal, <westphal@foo.fh-furtwangen.de>.
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ngIRCd -- The Next Generation IRC Daemon
 | 
			
		||||
 * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
 | 
			
		||||
 * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
 | 
			
		||||
 *
 | 
			
		||||
 * This program is free software; you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
@@ -13,13 +13,13 @@
 | 
			
		||||
 *
 | 
			
		||||
 * Code partially borrowed from compat.c of rsync, written by Andrew
 | 
			
		||||
 * Tridgell (1998) and Martin Pool (2002):
 | 
			
		||||
 * <http://samba.anu.edu.au/rsync/doxygen/head/lib_2compat_8c.html>
 | 
			
		||||
 * <http://cvs.samba.org/cgi-bin/cvsweb/rsync/lib/compat.c>
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "portab.h"
 | 
			
		||||
 | 
			
		||||
static char UNUSED id[] = "$Id: strlcpy.c,v 1.3 2005/01/18 09:05:37 alex Exp $";
 | 
			
		||||
static char UNUSED id[] = "$Id: strlcpy.c,v 1.4 2005/02/27 09:29:13 alex Exp $";
 | 
			
		||||
 | 
			
		||||
#include "imp.h"
 | 
			
		||||
#include <string.h>
 | 
			
		||||
@@ -40,9 +40,9 @@ strlcat( CHAR *dst, CONST CHAR *src, size_t size )
 | 
			
		||||
	size_t len2 = strlen( src );
 | 
			
		||||
	size_t ret = len1 + len2;
 | 
			
		||||
 | 
			
		||||
	if( len1 + len2 >= size ) len2 = size - ( len1 + 1 );
 | 
			
		||||
	if( len2 > 0 )
 | 
			
		||||
	{
 | 
			
		||||
	if( size && ( len1 < size - 1 )) {
 | 
			
		||||
		if( len2 >= size - len1 )
 | 
			
		||||
			len2 = size - len1 - 1;
 | 
			
		||||
		memcpy( dst + len1, src, len2 );
 | 
			
		||||
		dst[len1 + len2] = 0;
 | 
			
		||||
	}
 | 
			
		||||
@@ -63,10 +63,11 @@ strlcpy( CHAR *dst, CONST CHAR *src, size_t size )
 | 
			
		||||
	size_t len = strlen( src );
 | 
			
		||||
	size_t ret = len;
 | 
			
		||||
 | 
			
		||||
	if( size <= 0 ) return 0;
 | 
			
		||||
	if( len >= size ) len = size - 1;
 | 
			
		||||
	memcpy( dst, src, len );
 | 
			
		||||
	dst[len] = 0;
 | 
			
		||||
	if( size > 0 ) {
 | 
			
		||||
		if( len >= size ) len = size - 1;
 | 
			
		||||
		memcpy( dst, src, len );
 | 
			
		||||
		dst[len] = 0;
 | 
			
		||||
	}
 | 
			
		||||
	return ret;
 | 
			
		||||
} /* strlcpy */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user