You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/01/04 07:38:20 UTC

[GitHub] [tvm] liangfu commented on a change in pull request #7190: Makes sure g_last_error is null terminated.

liangfu commented on a change in pull request #7190:
URL: https://github.com/apache/tvm/pull/7190#discussion_r551154025



##########
File path: src/runtime/crt/common/crt_runtime_api.c
##########
@@ -38,7 +38,10 @@
 
 static char g_last_error[1024];
 
-void TVMAPISetLastError(const char* msg) { strncpy(g_last_error, msg, sizeof(g_last_error)); }
+void TVMAPISetLastError(const char* msg) {
+  strncpy(g_last_error, msg, sizeof(g_last_error) - 1);
+  g_last_error[sizeof(g_last_error) - 1] = 0;

Review comment:
       I think no null-character is implicitly appended at the end of destination only if source is longer than num, otherwise, destination is padded with zeros until a total of num characters have been written to it. See [strncpy - C++ reference](http://www.cplusplus.com/reference/cstring/strncpy/).
   
   The error reported in the compiler meant "bound 1024 equals destination size". As a correction for this, I think it'll be better to copy msg directly to g_last_error:
   ```c
   strcpy(g_last_error, msg);
   ```




----------------------------------------------------------------
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:
users@infra.apache.org