hunyadi-dev commented on a change in pull request #1020:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1020#discussion_r585516560



##########
File path: nanofi/include/sitetosite/CPeer.h
##########
@@ -74,8 +74,8 @@ static void setHostName(struct SiteToSiteCPeer * peer, const 
char * hostname) {
   peer->_url = (char*)malloc(host_len + 14);  // +1 for trailing zero, 1 for 
':', at most 5 for port, 7 for "nifi://" suffix
   memset(peer->_url, 0, host_len + 14);  // make sure to have zero padding no 
matter the length of the port
   strncpy(peer->_host, hostname, host_len);
-  strncpy(peer->_url, "nifi://", 7);
-  strncpy(peer->_url + 7, hostname, host_len);
+  memcpy(peer->_url, "nifi://", 7);

Review comment:
       Do you not just mask out the reported mistake of not copying `\0`?
   ```bash
   nifi://
   0123456 --> 7 characters copied, missing \0.
   ```
   
   **Update:**
   Now I see that the string is zeroed out beforehand. Maybe using 
`std::snprintf` would be more clear here.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to