Several minor bugfixes in handling BOOL values, fix crash in shrinking

mutable data.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18507 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-01-30 11:30:56 +00:00
parent ad63dfed22
commit 418907a03d
4 changed files with 46 additions and 32 deletions

View file

@ -2,6 +2,12 @@
* Source/NSString.m: Added two new MacOS-X initialisers.
* Headers/Foundation/NSString.h: ditto
* Source/NSData.m: ([replaceBytesInRange:withBytes:length:) rewrite
to fix crash when new data is smaller than orignal.
* Source/NSNumber.m: ([numberWithBool:]) and ([initWithBool:])
returns yes value for any non-zero argument. ([boolValue]) returns
either YES or NO. So we are tolerant in what we accept, strict in
what we produce.
2004-01-28 Fred Kiefer <FredKiefer@gmx.de>

View file

@ -117,7 +117,7 @@ enum {
#ifndef STRICT_OPENSTEP
- (id) initWithBytes: (const void*)bytes
length: (unsigned int)length
encoding: (NSStringEncoding)encoding ;
encoding: (NSStringEncoding)encoding;
- (id) initWithBytesNoCopy: (const void*)bytes
length: (unsigned int)length
encoding: (NSStringEncoding)encoding

View file

@ -1742,37 +1742,45 @@ failure:
unsigned size = [self length];
unsigned end = NSMaxRange(aRange);
int shift = length - aRange.length;
unsigned need = end + shift;
unsigned need = size + shift;
void *buf;
if (aRange.location > size)
{
[NSException raise: NSRangeException
format: @"location bad in replaceByteInRange:withBytes:"];
}
if (length > aRange.length)
{
need += (length - aRange.length);
}
if (need > size)
{
[self setLength: need];
}
if (aRange.length > 0 || aRange.length != length)
buf = [self mutableBytes];
if (shift < 0)
{
void *buf = [self mutableBytes];
if (end < size && shift != 0)
if (length > 0)
{
// Copy bytes into place.
memmove(buf + aRange.location, bytes, length);
}
// Fill gap
memmove(buf + end + shift, buf + end, size - end);
}
else
{
if (shift > 0)
{
// Open space
memmove(buf + end + shift, buf + end, size - end);
}
if (length > 0)
{
// Copy bytes into place.
memmove(buf + aRange.location, bytes, length);
}
}
if (shift < 0)
if (need < size)
{
[self setLength: need + shift];
[self setLength: need];
}
}

View file

@ -326,13 +326,13 @@ static Class doubleNumberClass;
+ (NSNumber*) numberWithBool: (BOOL)value
{
if (value == YES)
if (value == NO)
{
return boolY;
return boolN;
}
else
{
return boolN;
return boolY;
}
}
@ -507,13 +507,13 @@ static Class doubleNumberClass;
- (id) initWithBool: (BOOL)value
{
NSDeallocateObject(self);
if (value == YES)
if (value == NO)
{
self = boolY;
self = boolN;
}
else
{
self = boolN;
self = boolY;
}
return RETAIN(self);
}
@ -822,98 +822,98 @@ static Class doubleNumberClass;
BOOL oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 1:
{
signed char oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 2:
{
unsigned char oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 3:
{
signed short oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 4:
{
unsigned short oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 5:
{
signed int oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 6:
{
unsigned int oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 7:
{
signed long oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 8:
{
unsigned long oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 9:
{
signed long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 10:
{
unsigned long long oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 11:
{
float oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
case 12:
{
double oData;
(*(info->getValue))(self, @selector(getValue:), &oData);
return oData;
return (oData == 0) ? NO : YES;
}
default:
[NSException raise: NSInvalidArgumentException
format: @"unknown number type value for get"];
}
}
return 0;
return NO;
}
- (signed char) charValue