From f7b00a8d88694cdf9f36c449c5bd9bcec214e510 Mon Sep 17 00:00:00 2001 From: Tr4Dr Date: Mon, 18 Sep 2017 14:55:03 +0200 Subject: [PATCH] Added null check to convertSystemString [MT5] Whithout this fix, the OrderSend method crashing if we doesn't set the "request.Comment" property. --- MT5Connector/MT5Connector.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/MT5Connector/MT5Connector.cpp b/MT5Connector/MT5Connector.cpp index 137fb90f..130cbc77 100755 --- a/MT5Connector/MT5Connector.cpp +++ b/MT5Connector/MT5Connector.cpp @@ -51,9 +51,15 @@ public struct CMqlBookInfo void convertSystemString(wchar_t* dest, String^ src) { - pin_ptr wch = PtrToStringChars(src); - memcpy(dest, wch, wcsnlen(wch, 1000) * sizeof(wchar_t)); - dest[wcsnlen(wch, 1000)] = L'\0'; + if (src != nullptr) { + pin_ptr wch = PtrToStringChars(src); + memcpy(dest, wch, wcsnlen(wch, 1000) * sizeof(wchar_t)); + dest[wcsnlen(wch, 1000)] = L'\0'; + } + else + { + dest[0] = L'\0'; + } } #define _DLLAPI extern "C" __declspec(dllexport)