Skip to content

Commit

Permalink
Create temp array
Browse files Browse the repository at this point in the history
  • Loading branch information
uholeschak committed Dec 8, 2024
1 parent c320523 commit 4dd90e4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions EdiabasLib/Api32/ApiDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ static String ^ ConvertCString(const char far *string)
{
return String::Empty;
}

array<byte>^ bytes = gcnew array<byte>(length);
pin_ptr<byte> p = &bytes[0];
memcpy(p, string, length);
Expand All @@ -266,20 +267,26 @@ static array<byte> ^ ConvertNetString(String ^string, char far *buf, int bufsize
{
return nullptr;
}

if (string == nullptr)
{
buf[0] = 0;
return nullptr;
}
array<byte> ^ bytes = Ediabas::ApiInternal::Encoding->GetBytes(string);
int length = min(bytes->Length, bufsize - 1);
if (length > 0)

array<byte> ^ bytesEncode = Ediabas::ApiInternal::Encoding->GetBytes(string);
int length = min(bytesEncode->Length, bufsize - 1);
array<byte>^ bytesResult = gcnew array<byte>(length + 1);
for (size_t i = 0; i < length; i++)
{
pin_ptr<byte> p = &bytes[0];
memcpy_s(buf, bufsize, p, length);
bytesResult[i] = bytesEncode[i];
}
buf[length] = 0;
return bytes;
bytesResult[length] = 0;

pin_ptr<byte> p = &bytesResult[0];
memcpy_s(buf, bufsize, p, bytesResult->Length);

return bytesResult;
}

#ifdef __cplusplus
Expand Down

0 comments on commit 4dd90e4

Please sign in to comment.