将strtok改为strtok_r
authorhcj_ <1224667075@qq.com>
Tue, 30 Apr 2024 06:07:48 +0000 (14:07 +0800)
committerhcj_ <1224667075@qq.com>
Tue, 30 Apr 2024 06:07:48 +0000 (14:07 +0800)
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp

index 366c2a0..476463e 100755 (executable)
@@ -380,14 +380,21 @@ void MsgCenterNotifyCardProc(const Topic topic, Request* req)
     //green,red,ir
     int green,red,ir;
     char* str= (char *)req->data;
+    char *pchStrTmpIn = NULL;
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",str);
     char *tokbuf=NULL;
-    tokbuf=strtok(str,",");
+    tokbuf=strtok_r(str,",",&pchStrTmpIn);
+    if(tokbuf!=NULL)
     green=atoi(tokbuf);
-    tokbuf=strtok(NULL,",");
-    red=atoi(tokbuf);   
-    tokbuf=strtok(NULL,"\0");
+
+    tokbuf=strtok_r(NULL,",",&pchStrTmpIn);
+    if(tokbuf!=NULL)
+    red=atoi(tokbuf); 
+
+    tokbuf=strtok_r(NULL,"\0",&pchStrTmpIn);
+    if(tokbuf!=NULL)
     ir=atoi(tokbuf);
+
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d,%d,%d",green,red,ir);
 
     testhrsenson1View * t= testhrsenson1View::GetInstance();
@@ -406,14 +413,23 @@ void MsgCenterNotifyleaklightProc(const Topic topic, Request* req)
     //green,red,ir
     int green,red,ir;
     char* str= (char *)req->data;
+    char *pchStrTmpIn = NULL;
+    
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",str);
+
     char *tokbuf=NULL;
-    tokbuf=strtok(str,",");
+    tokbuf=strtok_r(str,",",&pchStrTmpIn);
+    if(tokbuf!=NULL)
     green=atoi(tokbuf);
-    tokbuf=strtok(NULL,",");
-    red=atoi(tokbuf);   
-    tokbuf=strtok(NULL,"\0");
+
+    tokbuf=strtok_r(NULL,",",&pchStrTmpIn);
+    if(tokbuf!=NULL)
+    red=atoi(tokbuf); 
+
+    tokbuf=strtok_r(NULL,"\0",&pchStrTmpIn);
+    if(tokbuf!=NULL)
     ir=atoi(tokbuf);
+    
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d,%d,%d",green,red,ir);
 
     testhrsenson1View * t= testhrsenson1View::GetInstance();