소스 검색

:bug: Correction bug encodage chaine de carac

Arthur Brandao 6 년 전
부모
커밋
3e36ee94f3
1개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 2
      Serveur/json_parser.c

+ 4 - 2
Serveur/json_parser.c

@@ -286,7 +286,8 @@ char* key_index(JsonParser* this, int index){
     }
     //Creation string d'accueil
     char* val;
-    val = malloc(this->key_length[index] * sizeof(char));
+    val = malloc((this->key_length[index] + 1) * sizeof(char)); //+1 pour \0
+    memset(val, 0, this->key_length[index] + 1);
     //Copie valeur
     strncpy(val, this->key[index], this->key_length[index]);
     //Retour
@@ -300,7 +301,8 @@ char* get_index(JsonParser* this, int index){
     }
     //Creation string d'accueil
     char* val;
-    val = malloc(this->val_length[index] * sizeof(char));
+    val = malloc((this->val_length[index] +1) * sizeof(char)); //+1 pour \0
+    memset(val, 0, this->val_length[index] + 1);
     //Copie valeur
     strncpy(val, this->val[index], this->val_length[index]);
     //Retour