MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / StringStrdup

Function StringStrdup

common/script/cstdlib/string.c:178–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176
177#ifndef WIN32
178void StringStrdup(
179 struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs)
180{
181 /* Through the script heap, not the C library's strdup: a script's free()
182 is ScriptHeap::release, which ignores a pointer the heap does not own, so
183 a libc strdup would leak for the whole run and log a warning per free.
184 Anything a script can free has to be allocated the way its malloc is. */
185 const char* src = Param[0]->Val->Pointer;
186 if (src == NULL)
187 {
188 ReturnValue->Val->Pointer = NULL;
189 return;
190 }
191
192 size_t size = strlen(src) + 1;
193 void* copy = ckpt_script_malloc(size);
194 if (copy != NULL)
195 {
196 memcpy(copy, src, size);
197 }
198 ReturnValue->Val->Pointer = copy;
199}
200
201void StringStrtok_r(
202 struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs)

Callers

nothing calls this directly

Calls 1

ckpt_script_mallocFunction · 0.85

Tested by

no test coverage detected