fix memory leak bug

This commit is contained in:
Xuan Sang LE
2018-03-14 11:55:15 +01:00
parent 5f12b8917a
commit 4679f6ab04
2 changed files with 12 additions and 5 deletions

View File

@ -81,11 +81,11 @@ char* __s(const char* fstring,...)
*/
void trim(char* str, const char delim)
{
if(!str) return;
if(!str || strlen(str) == 0) return;
char * p = str;
int l = strlen(p);
while(p[l - 1] == delim) p[--l] = 0;
while(l > 0 && p[l - 1] == delim)
p[--l] = 0;
while(* p && (* p) == delim ) ++p, --l;
memmove(str, p, l + 1);
}