MCPcopy Create free account
hub / github.com/HyperDbg/HyperDbg / InsertStrNew

Function InsertStrNew

hyperdbg/script-engine/code/script_include.c:72–92  ·  view source on GitHub ↗

* @brief Inserts a string into another string at a given index * * @param Str the original string (will be reallocated) * @param InputIdx the index at which to insert * @param Buf the string to insert * @return char * the new string, or the original on allocation failure */

Source from the content-addressed store, hash-verified

70 * @return char * the new string, or the original on allocation failure
71 */
72char *
73InsertStrNew(char * Str, int InputIdx, const char * Buf)
74{
75 SIZE_T LenStr = strlen(Str);
76 SIZE_T LenBuf = strlen(Buf);
77
78 if (InputIdx < 0 || (SIZE_T)InputIdx > LenStr)
79 return Str;
80
81 char * NewStr = (char *)realloc(Str, LenStr + LenBuf + 1);
82 if (!NewStr)
83 return Str;
84
85 memmove(NewStr + InputIdx + LenBuf,
86 NewStr + InputIdx,
87 LenStr - InputIdx + 1);
88
89 memcpy(NewStr + InputIdx, Buf, LenBuf);
90
91 return NewStr;
92}
93
94/**
95 * @brief Checks whether a file path is absolute

Callers 1

CodeGenFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected