Przeglądaj źródła

:bug:Correction ltrim

Arthur Brandao 6 lat temu
rodzic
commit
e3878c200c
1 zmienionych plików z 4 dodań i 4 usunięć
  1. 4 4
      Serveur/str.c

+ 4 - 4
Serveur/str.c

@@ -113,9 +113,9 @@ char* ltrim(char* str, char mask){
         return str;
     }
     //Sinon creation nouvelle chaine
-    res = malloc(sizeof(char) * (strlen(str) - cmpt));
-    for(int i = cmpt; i < strlen(str); i++){
-        res[i] = str[cmpt++];
+    res = malloc(sizeof(char) * (strlen(str) - cmpt + 1));
+    for(int i = 0, j = cmpt; i < (strlen(str) - cmpt); i++, j++){
+        res[i] = str[j];
     }
     //Retour nouvelle chaine
     return res;
@@ -135,7 +135,7 @@ char* rtrim(char* str, char mask){
     }
     cmpt++;
     //Sinon creation nouvelle chaine
-    res = malloc(sizeof(char) * (cmpt + 1));
+    res = malloc(sizeof(char) * (cmpt + 2));
     for(int i = 0; i < cmpt; i++){
         res[i] = str[i];
     }