Browse Source

Stack: Avoid string copy and just use reference

Stefan Profanter 5 years ago
parent
commit
72b1cbca6c
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/client/ua_client_connect.c

+ 4 - 1
src/client/ua_client_connect.c

@@ -99,13 +99,16 @@ HelAckHandshake(UA_Client *client, const UA_String endpointUrl) {
 
     /* Prepare the HEL message and encode at offset 8 */
     UA_TcpHelloMessage hello;
-    UA_String_copy(&endpointUrl, &hello.endpointUrl); /* must be less than 4096 bytes */
+    /* just reference to avoid copy */
+    hello.endpointUrl = endpointUrl;
     memcpy(&hello, &client->config.localConnectionConfig,
            sizeof(UA_ConnectionConfig)); /* same struct layout */
 
     UA_Byte *bufPos = &message.data[8]; /* skip the header */
     const UA_Byte *bufEnd = &message.data[message.length];
     retval = UA_TcpHelloMessage_encodeBinary(&hello, &bufPos, bufEnd);
+    /* avoid deleting reference */
+    hello.endpointUrl = UA_STRING_NULL;
     UA_TcpHelloMessage_deleteMembers(&hello);
     if(retval != UA_STATUSCODE_GOOD) {
         conn->releaseSendBuffer(conn, &message);