gcc 4.3.2 detects the use of memset() with zero for the length
parameter. I'm not sure if this is a new thing for glibc that gcc is
finally checking but in any case it showed up in Ubuntu Intrepid.

There are some template classes whos methods are passed values that
result in memset being called with a zero length. Because the
definitions are in header files these calls are inlined, so even
though its a method call because it is inlined gcc can see that the
value results in the memset length always being zero.

In my case I'm seeing compile warnings and failure during linking to
find the __warn_memset_zero_len function.

The attached patch adds checking of the memset length parameter in the
few locations that gcc warned about, skipping the call to memset if
the length value is zero.

Chris

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [EMAIL PROTECTED]
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Index: libs/crypto++/misc.h
===================================================================
--- libs/crypto++/misc.h	(revision 1407)
+++ libs/crypto++/misc.h	(working copy)
@@ -793,7 +793,8 @@
 	const size_t U = sizeof(T);
 	assert(inlen <= outlen*U);
 	memcpy(out, in, inlen);
-	memset((byte *)out+inlen, 0, outlen*U-inlen);
+	if((outlen*U-inlen) != 0)
+		memset((byte *)out+inlen, 0, outlen*U-inlen);
 	ConditionalByteReverse(order, out, out, RoundUpToMultipleOf(inlen, U));
 }
 
Index: libs/crypto++/secblock.h
===================================================================
--- libs/crypto++/secblock.h	(revision 1407)
+++ libs/crypto++/secblock.h	(working copy)
@@ -130,7 +130,8 @@
 
 	void deallocate(void *p, size_type n)
 	{
-		memset(p, 0, n*sizeof(T));
+		if((n*sizeof(T)) != 0)
+			memset(p, 0, n*sizeof(T));
 
 		if (T_Align16 && n*sizeof(T) >= 16)
 		{
@@ -288,9 +289,14 @@
 	{
 		m_ptr = m_alloc.allocate(len, NULL);
 		if (t == NULL)
-			memset(m_ptr, 0, len*sizeof(T));
+		{
+			if((len * sizeof(T)) != 0)
+				memset(m_ptr, 0, len*sizeof(T));
+		}
 		else
+		{
 			memcpy(m_ptr, t, len*sizeof(T));
+		}
 	}
 
 	~SecBlock()

Reply via email to