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

Method UpdateName

source/script_menu.cpp:818–844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

816
817
818ResultType UserMenu::UpdateName(UserMenuItem *aMenuItem, LPTSTR aNewName)
819// Caller should already have ensured that aMenuItem is not too long.
820{
821 size_t new_length = _tcslen(aNewName);
822 if (new_length)
823 {
824 if (new_length >= aMenuItem->mNameCapacity) // Too small, so reallocate.
825 {
826 // Use a temp var. so that mName will never wind up being NULL (relied on by other things).
827 // This also retains the original menu name if the allocation fails:
828 LPTSTR temp = tmalloc(new_length + 1); // +1 for terminator.
829 if (!temp)
830 return FAIL;
831 // Otherwise:
832 if (aMenuItem->mName != Var::sEmptyString) // Since it was previously allocated, free it.
833 free(aMenuItem->mName);
834 aMenuItem->mName = temp;
835 aMenuItem->mNameCapacity = new_length + 1;
836 }
837 _tcscpy(aMenuItem->mName, aNewName);
838 }
839 else // It will become a separator.
840 {
841 *aMenuItem->mName = '\0'; // Safe because even if it's capacity is 1 byte, it's a writable byte.
842 }
843 return OK;
844}
845
846
847

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected