MCPcopy Create free account
hub / github.com/dobin/RedEdr / JsonEscape

Function JsonEscape

RedEdrShared/utils.cpp:383–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381}
382
383wchar_t* JsonEscape(wchar_t* str, size_t buffer_size) {
384 if (str == NULL || buffer_size == 0) {
385 str;
386 }
387
388 size_t length = 0;
389 for (length = 0; str[length] != L'\0'; ++length);
390
391 for (size_t i = 0; i < length; ++i) {
392 if (str[i] == L'\\' || str[i] == L'"') {
393 // Check if there's enough space to shift and insert escape character
394 if (length + 1 >= buffer_size) {
395 return str; // Stop processing to prevent overflow
396 }
397
398 // Shift the remainder of the string one position to the right
399 for (size_t j = length + 1; j > i; --j) {
400 str[j] = str[j - 1];
401 }
402
403 // Insert escape character
404 str[i] = L'\\';
405 ++i; // Skip over the character we just escaped
406 ++length;
407 }
408 }
409 return str;
410}
411
412
413DWORD StartProcessInBackground(LPCWSTR exePath, LPCWSTR commandLine) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected