USNavalResearchLaboratory / norm

NACK-Oriented Reliable Multicast (NORM) implementation & tools (RFCs 5740, 5401)
https://www.nrl.navy.mil/Our-Work/Areas-of-Research/Information-Technology/NCS/NORM/
Other
100 stars 36 forks source link

2 compiler warnings seem to indicate errors #83

Closed paultol closed 10 months ago

paultol commented 12 months ago

While compiling normApp.cpp

../src/common/normApp.cpp:617:20: warning: ‘void operator delete(void*, long unsigned int)’ called on pointer returned from a mismatched allocation function [-Wmismatched-new-delete]
  617 |             delete address;
      |                    ^~~~~~~
../src/common/normApp.cpp:607:39: note: returned from ‘void* operator new [](long unsigned int)’
  607 |         if (!(address = new char[len+1]))

and

../src/common/normPostProcess.cpp: In member function ‘void NormPostProcessor::GetCommand(char*, unsigned int)’:
../src/common/normPostProcess.cpp:51:20: warning: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 4 bytes from a string of the same length [-Wstringop-truncation]
   51 |             strncpy(buffer, "none", 4);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~

both seem to indicate genuine errors.

The former should be changed to "delete[] address" (also in the lines 606 and 626 even though g++ did not notice).

About the latter, I am not sure as the enclosing function NormPostProcessor::GetCommand does not seem to be used so intentions are unclear. Unless it is there for future use, I think the safest would be to remove the function.

bebopagogo commented 10 months ago

I just pushed a commit that addresses these comments/issues. Thank you for your input!