summaryrefslogtreecommitdiffstats
path: root/generic/tclHash.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2025-04-13 22:16:52 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2025-04-13 22:16:52 (GMT)
commit2b0fe4a3ef75940978059b4b33672f2d1c63dced (patch)
tree4d6908ac453dc6ccba9b0a0593e77af3511609c6 /generic/tclHash.c
parentd46e9784ab0ff5b3e9bf35dc56c903fd9503c936 (diff)
downloadtcl-core-attemptcreatehashentry.zip
tcl-core-attemptcreatehashentry.tar.gz
tcl-core-attemptcreatehashentry.tar.bz2
Implement Tcl_AttemptCreateHashEntry()core-attemptcreatehashentry
Diffstat (limited to 'generic/tclHash.c')
-rw-r--r--generic/tclHash.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c
index 518ba93..1b4d644 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -335,7 +335,10 @@ CreateHashEntry(
if (typePtr->allocEntryProc) {
hPtr = typePtr->allocEntryProc(tablePtr, (void *) key);
} else {
- hPtr = (Tcl_HashEntry *)Tcl_Alloc(sizeof(Tcl_HashEntry));
+ hPtr = (Tcl_HashEntry *)Tcl_AttemptAlloc(sizeof(Tcl_HashEntry));
+ if (!hPtr) {
+ return NULL;
+ }
hPtr->key.oneWordValue = (char *) key;
Tcl_SetHashValue(hPtr, NULL);
}
@@ -681,10 +684,12 @@ AllocArrayEntry(
if (size < sizeof(Tcl_HashEntry)) {
size = sizeof(Tcl_HashEntry);
}
- hPtr = (Tcl_HashEntry *)Tcl_Alloc(size);
+ hPtr = (Tcl_HashEntry *)Tcl_AttemptAlloc(size);
- memcpy(hPtr->key.string, keyPtr, count);
- Tcl_SetHashValue(hPtr, NULL);
+ if (hPtr) {
+ memcpy(hPtr->key.string, keyPtr, count);
+ Tcl_SetHashValue(hPtr, NULL);
+ }
return hPtr;
}
@@ -779,10 +784,12 @@ AllocStringEntry(
if (size < sizeof(hPtr->key)) {
allocsize = sizeof(hPtr->key);
}
- hPtr = (Tcl_HashEntry *)Tcl_Alloc(offsetof(Tcl_HashEntry, key) + allocsize);
- memset(hPtr, 0, offsetof(Tcl_HashEntry, key) + allocsize);
- memcpy(hPtr->key.string, string, size);
- Tcl_SetHashValue(hPtr, NULL);
+ hPtr = (Tcl_HashEntry *)Tcl_AttemptAlloc(offsetof(Tcl_HashEntry, key) + allocsize);
+ if (hPtr) {
+ memset(hPtr, 0, offsetof(Tcl_HashEntry, key) + allocsize);
+ memcpy(hPtr->key.string, string, size);
+ Tcl_SetHashValue(hPtr, NULL);
+ }
return hPtr;
}