Quellcode durchsuchen

:bug: Correction bug encodage chaine de carac

Arthur Brandao vor 6 Jahren
Ursprung
Commit
3e36ee94f3
1 geänderte Dateien mit 4 neuen und 2 gelöschten Zeilen
  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