浏览代码

fixbug: setproctitle when main_ctx_init not called before

hewei 6 年之前
父节点
当前提交
a03dc9bf9f
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      utils/hmain.cpp

+ 3 - 1
utils/hmain.cpp

@@ -283,7 +283,9 @@ const char* get_env(const char* key) {
 void setproctitle(const char* title) {
     //printf("proctitle=%s\n", title);
     int len = g_main_ctx.arg_len + g_main_ctx.env_len;
-    strncpy(g_main_ctx.os_argv[0], title, len-1);
+    if (g_main_ctx.os_argv && len) {
+        strncpy(g_main_ctx.os_argv[0], title, len-1);
+    }
 }
 #endif