MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / TokenSetResult

Function TokenSetResult

source/script2.cpp:17157–17178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17155
17156
17157ResultType TokenSetResult(ResultToken &aResultToken, LPCTSTR aValue, size_t aLength)
17158// Utility function for handling memory allocation and return to callers of built-in functions; based on BIF_SubStr.
17159// Returns FAIL if malloc failed, in which case our caller is responsible for returning a sensible default value.
17160{
17161 if (aLength == -1)
17162 aLength = _tcslen(aValue); // Caller must not pass NULL for aResult in this case.
17163 if (aLength <= MAX_NUMBER_LENGTH) // v1.0.46.01: Avoid malloc() for small strings. However, this improves speed by only 10% in a test where random 25-byte strings were extracted from a 700 KB string (probably because VC++'s malloc()/free() are very fast for small allocations).
17164 aResultToken.marker = aResultToken.buf; // Store the address of the result for the caller.
17165 else
17166 {
17167 // Caller has provided a mem_to_free (initially NULL) as a means of passing back memory we allocate here.
17168 // So if we change "result" to be non-NULL, the caller will take over responsibility for freeing that memory.
17169 if ( !(aResultToken.mem_to_free = tmalloc(aLength + 1)) ) // Out of memory.
17170 return aResultToken.MemoryError();
17171 aResultToken.marker = aResultToken.mem_to_free; // Store the address of the result for the caller.
17172 }
17173 if (aValue) // Caller may pass NULL to retrieve a buffer of sufficient size.
17174 tmemcpy(aResultToken.marker, aValue, aLength);
17175 aResultToken.marker[aLength] = '\0'; // Must be done separately from the memcpy() because the memcpy() might just be taking a substring (i.e. long before result's terminator).
17176 aResultToken.marker_length = aLength;
17177 return OK;
17178}
17179
17180
17181

Callers 15

InvokeMethod · 0.85
ControlGetComboBoxMethod · 0.85
ControlGetListBoxMethod · 0.85
ControlGetWindowTextMethod · 0.85
BIF_DECLFunction · 0.85
InvokeMethod · 0.85
ReturnMoveMethod · 0.85
RegReadFunction · 0.85
BIF_DECLFunction · 0.85
ControlGetListViewFunction · 0.85
script2.cppFile · 0.85
BIV_DECL_RFunction · 0.85

Calls 1

MemoryErrorMethod · 0.80

Tested by

no test coverage detected