Ver código fonte

fix:Fix allContent is null pointer problem

Rbb666 7 meses atrás
pai
commit
d3a77f4ae8
1 arquivos alterados com 10 adições e 4 exclusões
  1. 10 4
      ports/chat_port.c

+ 10 - 4
ports/chat_port.c

@@ -28,7 +28,7 @@
 static char authHeader[128] = {0};
 static char responseBuffer[WEB_SOCKET_BUF_SIZE] = {0};
 static char contentBuffer[WEB_SOCKET_BUF_SIZE] = {0};
-static char *allContent = RT_NULL;
+static char allContent[WEB_SOCKET_BUF_SIZE] = {0};
 
 /**
  * @brief: create char for request payload.
@@ -129,9 +129,11 @@ void clear_messages(struct llm_obj *handle)
  **/
 char *get_llm_answer(cJSON *messages)
 {
-    struct webclient_session *webSession = NULL;
-    char *payload = NULL;
+    struct webclient_session *webSession = RT_NULL;
+    char *payload = RT_NULL;
+    char *result = RT_NULL;
     int bytesRead, responseStatus;
+
     allContent[0] = '\0';
 
     // check the messages is array
@@ -239,5 +241,9 @@ cleanup:
         cJSON_free(payload);
     }
 
-    return rt_strdup(allContent);
+    if (allContent[0] != '\0')
+    {
+        result = rt_strdup(allContent);
+    }
+    return result;
 }