From c3a18c19366fc1c5c4fec43cc57952fbfa838ae3 Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Sat, 9 Mar 2002 02:49:12 +0000 Subject: [PATCH] Fix bug # 124919: get LDAP searches in Addrbook working on Mac OS X. r=dmose sr=ben a=asa git-svn-id: svn://10.0.0.236/trunk@116252 18797224-902f-48f8-a5cc-f745e15eee43 --- .../directory/xpcom/base/src/nsLDAPURL.cpp | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/mozilla/directory/xpcom/base/src/nsLDAPURL.cpp b/mozilla/directory/xpcom/base/src/nsLDAPURL.cpp index 3e1f151c880..a8ff3bc9a4d 100644 --- a/mozilla/directory/xpcom/base/src/nsLDAPURL.cpp +++ b/mozilla/directory/xpcom/base/src/nsLDAPURL.cpp @@ -425,7 +425,7 @@ NS_IMETHODIMP nsLDAPURL::GetAttributes(PRUint32 *aCount, char ***_retval) { PRUint32 index = 0; PRUint32 count; - char **cArray; + char **cArray = nsnull; if (!_retval) { NS_ERROR("nsLDAPURL::GetAttributes: null pointer "); @@ -433,21 +433,23 @@ NS_IMETHODIMP nsLDAPURL::GetAttributes(PRUint32 *aCount, char ***_retval) } count = mAttributes->Count(); - cArray = NS_STATIC_CAST(char **, nsMemory::Alloc(count * sizeof(char *))); - if (!cArray) { - NS_ERROR("nsLDAPURL::GetAttributes: out of memory "); - return NS_ERROR_OUT_OF_MEMORY; - } - - // Loop through the string array, and build up the C-array. - // - while (index < count) { - if (!(cArray[index] = ToNewCString(*(mAttributes->CStringAt(index))))) { - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(index, cArray); + if (count > 0) { + cArray = NS_STATIC_CAST(char **, nsMemory::Alloc(count * sizeof(char *))); + if (!cArray) { NS_ERROR("nsLDAPURL::GetAttributes: out of memory "); return NS_ERROR_OUT_OF_MEMORY; } - index++; + + // Loop through the string array, and build up the C-array. + // + while (index < count) { + if (!(cArray[index] = ToNewCString(*(mAttributes->CStringAt(index))))) { + NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(index, cArray); + NS_ERROR("nsLDAPURL::GetAttributes: out of memory "); + return NS_ERROR_OUT_OF_MEMORY; + } + index++; + } } *aCount = count; *_retval = cArray;