Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Source/GSHashTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,12 @@ GSHashTableCreate (CFAllocatorRef alloc, CFTypeID typeID,
{
bucket = GSHashTableFindBucket (new, keys[idx],
_kGSHashTableInsert);
GSHashTableAddKeyValuePair (new, bucket, keys[idx], values[idx]);
new->_count += 1;
if (bucket->count <= 0)
{
GSHashTableAddKeyValuePair (new, bucket, keys[idx],
values[idx]);
new->_count += 1;
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions Tests/CFDictionary/create_duplicates.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "CoreFoundation/CFDictionary.h"
#include "CoreFoundation/CFString.h"
#include "../CFTesting.h"

int main (void)
{
const void *keys[2];
const void *values[2];
CFDictionaryRef dict;

keys[0] = CFSTR ("k");
keys[1] = CFSTR ("k");
values[0] = CFSTR ("v1");
values[1] = CFSTR ("v2");

dict = CFDictionaryCreate (NULL, keys, values, 2,
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
PASS_CF(CFDictionaryGetCount (dict) == 1,
"A key repeated in the input array is stored once.");
PASS_CF(CFDictionaryContainsKey (dict, CFSTR ("k")),
"The key is present.");

CFRelease (dict);

return 0;
}
24 changes: 24 additions & 0 deletions Tests/CFSet/create_duplicates.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "CoreFoundation/CFSet.h"
#include "CoreFoundation/CFString.h"
#include "../CFTesting.h"

int main (void)
{
const void *values[3];
CFSetRef set;

values[0] = CFSTR ("a");
values[1] = CFSTR ("b");
values[2] = CFSTR ("a");

set = CFSetCreate (NULL, values, 3, &kCFTypeSetCallBacks);
PASS_CF(CFSetGetCount (set) == 2,
"A value repeated in the input array is stored once.");
PASS_CF(CFSetContainsValue (set, CFSTR ("a"))
&& CFSetContainsValue (set, CFSTR ("b")),
"Both distinct values are present.");

CFRelease (set);

return 0;
}
Loading