Skip to content
Snippets Groups Projects
Commit 31abf30a authored by rswindell's avatar rswindell
Browse files

truncsp() and truncstr() don't overwrite 0-terminator if's already there

(avoids segfaults when accidentally called with string constants).
parent ddd39aa2
No related branches found
No related tags found
No related merge requests found
......@@ -234,11 +234,12 @@ char* DLLCALL ultoac(ulong l, char *string)
/****************************************************************************/
char* DLLCALL truncsp(char *str)
{
uint c;
size_t c;
c=strlen(str);
while(c && (uchar)str[c-1]<=' ') c--;
str[c]=0;
if(str[c]!=0)
str[c]=0;
return(str);
}
......@@ -250,7 +251,7 @@ char* DLLCALL truncstr(char* str, const char* set)
char* p;
p=strpbrk(str,set);
if(p!=NULL)
if(p!=NULL && *p!=0)
*p=0;
return(p);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment