Fix leaks and a possible buffer overrun

This commit is contained in:
rfm 2024-11-17 12:55:55 +00:00
parent 5b46efa8cd
commit 0fb9739f21
4 changed files with 14 additions and 5 deletions

View file

@ -1770,7 +1770,13 @@ NSDictionary *locale)
if (-1 == prec)
{
len = strlen(str); // Number of bytes to convert.
/* Find end of string, within the specified limit.
*/
len = 0;
while (str[len] != '\0' && len < width)
{
len++;
}
blen = len; // Size of unichar output buffer.
}
else

View file

@ -43,6 +43,7 @@ int main()
encoding: NSISOLatin1StringEncoding];
PASS(str != nil && [str rangeOfString: @"sent to deallocated"].length > 0,
"was able to read zombie message from subtask");
RELEASE(str);
[task terminate];
[arp release];

View file

@ -14,7 +14,7 @@ int main(int argc, char **argv)
0x80, 0x1f, 0x3a, 0x01, 0x95, 0x7c, 0x45, 0x0f,
0xaf, 0xf2, 0x1b, 0xe9, 0x59, 0xf5, 0x89, 0x54 };
TEST_FOR_CLASS(@"NSUUID", [NSUUID alloc],
TEST_FOR_CLASS(@"NSUUID", AUTORELEASE([NSUUID alloc]),
"+[NSUUID alloc] returns a NSUUID");
TEST_FOR_CLASS(@"NSUUID", [NSUUID UUID],
"+[NSUUID UUID] returns a UUID");
@ -22,9 +22,11 @@ int main(int argc, char **argv)
uuid1 = [[NSUUID alloc] initWithUUIDString: nil];
PASS(uuid1 == nil, "Don't create a UUID from a nil string");
DESTROY(uuid1);
uuid1 = [[NSUUID alloc] initWithUUIDString: @"test"];
PASS(uuid1 == nil, "Don't create a UUID from an invalid string");
DESTROY(uuid1);
uuid1 = [[NSUUID alloc] initWithUUIDString: uuidString];
PASS(uuid1 != nil, "Create a UUID from a valid string");
PASS_EQUAL([uuid1 UUIDString], uuidString,
@ -43,12 +45,12 @@ int main(int argc, char **argv)
int comparison = memcmp(uuidBytes, otherBytes, 16);
PASS(comparison == 0, "Get a stable value for the UUID bytes");
DESTROY(uuid2);
DESTROY(uuid2);
uuid2 = [uuid1 copy];
PASS_EQUAL(uuid1, uuid2, "-[NSUUID copy] returns an identical object");
DESTROY(uuid2);
NSData *coded = [NSKeyedArchiver archivedDataWithRootObject: uuid1];
uuid2 = [NSKeyedUnarchiver unarchiveObjectWithData: coded];
PASS_EQUAL(uuid1, uuid2, "UUID survives a round-trip through archiver");

View file

@ -5,7 +5,7 @@
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSUserDefaults *defs = [NSUserDefaults new];
NSUserDefaults *defs = AUTORELEASE([NSUserDefaults new]);
test_NSObject(@"NSUserDefaults", [NSArray arrayWithObject: defs]);