From 9cdb4f98ba77165cfa838c17ceb961999200b0fa Mon Sep 17 00:00:00 2001 From: rfm Date: Sat, 30 Nov 2024 19:06:40 +0000 Subject: [PATCH] asan fixes for gcc and gnu runtime --- Source/NSThread.m | 5 ++++- Tests/base/NSString/NSString_tests.h | 7 +++---- Tests/base/NSString/NSString_zero_hash.m | 3 ++- Tests/base/NSString/noncharacter.m | 2 ++ Tests/base/NSString/nuls_in_strings.m | 2 ++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/NSThread.m b/Source/NSThread.m index 0d29b7cce8..70ed46b454 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -1399,7 +1399,8 @@ - (void) _setName: (NSString *)aName */ if (i > 15) { - NSWarnLog(@"Truncating thread name '%s' to 15 characters due to platform limitations", buf); + NSWarnLog(@"Truncating thread name '%s' to 15 characters" + @" due to platform limitations", buf); i = 15; } else @@ -1467,6 +1468,7 @@ - (NSUInteger) stackSize setThreadForCurrentThread(t); + ENTER_POOL /* * Let observers know a new thread is starting. */ @@ -1479,6 +1481,7 @@ - (NSUInteger) stackSize userInfo: nil]; [t _setName: [t name]]; + LEAVE_POOL [t main]; diff --git a/Tests/base/NSString/NSString_tests.h b/Tests/base/NSString/NSString_tests.h index f99fc99202..7ce5b4d87b 100644 --- a/Tests/base/NSString/NSString_tests.h +++ b/Tests/base/NSString/NSString_tests.h @@ -175,8 +175,8 @@ test_encoding(void) BOOL test_getCString_maxLength_range_remainingRange(void) { NS_DURING - unsigned char *referenceBytes; - int referenceBytesLength; + unsigned char referenceBytes[4]; + int referenceBytesLength = 4; NSString *referenceString; unsigned char buffer[16]; NSRange remainingRange; @@ -186,8 +186,7 @@ BOOL test_getCString_maxLength_range_remainingRange(void) switch ([NSString defaultCStringEncoding]) { case NSUTF8StringEncoding: - referenceBytes =(unsigned char []){0x41, 0xc3, 0xa5, 0x42}; - referenceBytesLength = 4; + memcpy(referenceBytes, (unsigned char []){0x41, 0xc3, 0xa5, 0x42}, 4); referenceString = [stringClass stringWithCharacters: (unichar []){0x41, 0xe5, 0x42} length: 3]; diff --git a/Tests/base/NSString/NSString_zero_hash.m b/Tests/base/NSString/NSString_zero_hash.m index 2309e54e62..32c0b78964 100644 --- a/Tests/base/NSString/NSString_zero_hash.m +++ b/Tests/base/NSString/NSString_zero_hash.m @@ -8,6 +8,7 @@ int main(int argc, char **argv) { + START_SET("zero hash") NSString *s = @"!)9\" ;"; unsigned int h; @@ -34,7 +35,7 @@ Generate a (hopefully ASCII printable) string with a given hash. s = [NSString stringWithString: s]; h = [s hash]; PASS(h != 0, "[NSString hash] does not return 0"); - + END_SET("zero hash") return 0; } diff --git a/Tests/base/NSString/noncharacter.m b/Tests/base/NSString/noncharacter.m index 157f09c3ba..3974a2425d 100644 --- a/Tests/base/NSString/noncharacter.m +++ b/Tests/base/NSString/noncharacter.m @@ -6,6 +6,7 @@ int main(int argc, char **argv) { + START_SET("noncharacter") NSString *str; unichar u; unichar u2[2]; @@ -42,6 +43,7 @@ int main(int argc, char **argv) PASS([str characterAtIndex: 0] == 0xffff, "ffff is returned properly"); [str release]; + END_SET("noncharacter") return 0; } diff --git a/Tests/base/NSString/nuls_in_strings.m b/Tests/base/NSString/nuls_in_strings.m index 87a19c2ba8..c71d3d58f5 100644 --- a/Tests/base/NSString/nuls_in_strings.m +++ b/Tests/base/NSString/nuls_in_strings.m @@ -11,6 +11,7 @@ int main(int argc, char **argv) { + START_SET("nuls in strings") NSString *constantString=@"a\0b"; NSString *normalString; unichar characters[3]={'a',0,'b'}; @@ -26,6 +27,7 @@ int main(int argc, char **argv) r = [normalString rangeOfString: @"\0"]; PASS(1 == r.length && 1 == r.location, "find nul in string"); + END_SET("nuls in strings") return 0; }