Skip to content

Commit 873a423

Browse files
committed
Some methods swap the number of elements and the size arguments
For calloc, the variable denoting the of elements comes first, then the variable denoting the size of each element. However, both arguments are swapped when calling this function in many places in this codebase.
1 parent f08f86c commit 873a423

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

include/swift/SwiftRemoteMirror/SwiftRemoteMirrorLegacyInterop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ swift_reflection_interop_createReflectionContextWithDataLayout(
667667
GetSymbolAddressFunction GetSymbolAddress) {
668668

669669
SwiftReflectionInteropContextRef ContextRef =
670-
(SwiftReflectionInteropContextRef)calloc(sizeof(*ContextRef), 1);
670+
(SwiftReflectionInteropContextRef)calloc(1, sizeof(*ContextRef));
671671

672672
ContextRef->ReaderContext = ReaderContext;
673673
ContextRef->DataLayout = DataLayout;

stdlib/public/runtime/Metadata.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,10 +3638,10 @@ initGenericObjCClass(ClassMetadata *self, size_t numFields,
36383638
if (numFields <= NumInlineGlobalIvarOffsets) {
36393639
_globalIvarOffsets = _inlineGlobalIvarOffsets;
36403640
// Make sure all the entries start out null.
3641-
memset(_globalIvarOffsets, 0, sizeof(size_t *) * numFields);
3641+
memset(_globalIvarOffsets, 0, numFields * sizeof(size_t *));
36423642
} else {
36433643
_globalIvarOffsets =
3644-
static_cast<size_t **>(calloc(sizeof(size_t *), numFields));
3644+
static_cast<size_t **>(calloc(numFields, sizeof(size_t *)));
36453645
}
36463646
}
36473647
return _globalIvarOffsets;

unittests/runtime/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static TestActor *createActor() {
114114
// swift_getTypeName will tolerate it. Otherwise we crash when trying to
115115
// signpost actor creation.
116116
descriptor =
117-
reinterpret_cast<ClassDescriptor *>(calloc(sizeof(*descriptor), 1));
117+
reinterpret_cast<ClassDescriptor *>(calloc(1, sizeof(*descriptor)));
118118
TestActorMetadata.setDescription(descriptor);
119119
}
120120
return new TestActor();

0 commit comments

Comments
 (0)