From 680d4eddb4addc0d9e0348c380a093527ecc25fe Mon Sep 17 00:00:00 2001 From: CaS Date: Fri, 27 Jul 2001 13:30:31 +0000 Subject: [PATCH] Fix bug with empty data object in xml plist git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@10592 72102866-910b-0410-8b05-ffd578937521 --- Source/GSCompatibility.m | 10 ++++++++-- Source/NSData.m | 2 ++ Source/NSString.m | 14 +++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Source/GSCompatibility.m b/Source/GSCompatibility.m index 29d06ede6..f67ff0c6b 100644 --- a/Source/GSCompatibility.m +++ b/Source/GSCompatibility.m @@ -143,11 +143,17 @@ encodeBase64(NSData *source) int enclen = length / 3; int remlen = length - 3 * enclen; int destlen = 4 * ((length - 1) / 3) + 5; - unsigned char *sBuf = (unsigned char*)[source bytes]; - unsigned char *dBuf = NSZoneMalloc(NSDefaultMallocZone(), destlen); + unsigned char *sBuf; + unsigned char *dBuf; int sIndex = 0; int dIndex = 0; + if (length == 0) + { + return @""; + } + sBuf = (unsigned char*)[source bytes]; + dBuf = NSZoneMalloc(NSDefaultMallocZone(), destlen); dBuf[destlen - 1] = '\0'; for (sIndex = 0; sIndex < length - 2; sIndex += 3, dIndex += 4) diff --git a/Source/NSData.m b/Source/NSData.m index 70c3456ca..e353a4b53 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -571,12 +571,14 @@ failure: NSZone *z; extern BOOL GSMacOSXCompatiblePropertyLists(); +/* Don't think we want this if (GSMacOSXCompatiblePropertyLists() == YES) { extern NSString *GSXMLPlMake(id obj, NSDictionary *loc, unsigned lev); return GSXMLPlMake(self, nil, 0); } +*/ src = [self bytes]; length = [self length]; diff --git a/Source/NSString.m b/Source/NSString.m index 5c0bffd2a..3051eecdb 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -3817,11 +3817,19 @@ static NSData* decodeBase64(const char *source) { int length = strlen(source); - char *sourceBuffer = objc_malloc(length+1); - NSMutableData *data = [NSMutableData dataWithCapacity:0]; - int i, j; + char *sourceBuffer; + NSMutableData *data; + int i; + int j; unsigned char tmp[4]; + if (length == 0) + { + return [NSData data]; + } + + data = [NSMutableData dataWithCapacity: 0]; + sourceBuffer = objc_malloc(length+1); strcpy(sourceBuffer, source); j = 0;