소스 검색

Fix for printing values that contain % literals. Thanks to Jimmy Tam!

git-svn-id: http://svn.code.sf.net/p/cjson/code@11 e3330c51-1366-4df0-8b21-3ccf24e3d50e
Dave Gamble 15 년 전
부모
커밋
37da1d2493
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 3
      cJSON.c

+ 3 - 3
cJSON.c

@@ -312,7 +312,7 @@ static char *print_array(cJSON *item,int depth)
 		len+=strlen(ret)+3;
 		len+=strlen(ret)+3;
 		out=(char*)cJSON_realloc(out,len);
 		out=(char*)cJSON_realloc(out,len);
 		ptr=out+strlen(out);
 		ptr=out+strlen(out);
-		ptr+=sprintf(ptr,ret);
+		ptr+=sprintf(ptr,"%s",ret);
 		if (child->next) {*ptr++=',';*ptr++=' ';*ptr=0;}
 		if (child->next) {*ptr++=',';*ptr++=' ';*ptr=0;}
 		child=child->next;
 		child=child->next;
 		cJSON_free(ret);
 		cJSON_free(ret);
@@ -374,9 +374,9 @@ static char *print_object(cJSON *item,int depth)
 		out=(char*)cJSON_realloc(out,len);
 		out=(char*)cJSON_realloc(out,len);
 		ptr=out+strlen(out);
 		ptr=out+strlen(out);
 		for (i=0;i<depth;i++) *ptr++='\t';
 		for (i=0;i<depth;i++) *ptr++='\t';
-		ptr+=sprintf(ptr,str);
+		ptr+=sprintf(ptr,"%s",str);
 		*ptr++=':';*ptr++='\t';
 		*ptr++=':';*ptr++='\t';
-		ptr+=sprintf(ptr,ret);
+		ptr+=sprintf(ptr,"%s",ret);
 		if (child->next) *ptr++=',';
 		if (child->next) *ptr++=',';
 		*ptr++='\n';*ptr=0;
 		*ptr++='\n';*ptr=0;
 		child=child->next;
 		child=child->next;