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,10 +234,11 @@ char* DLLCALL ultoac(ulong l, char *string) ...@@ -234,10 +234,11 @@ char* DLLCALL ultoac(ulong l, char *string)
/****************************************************************************/ /****************************************************************************/
char* DLLCALL truncsp(char *str) char* DLLCALL truncsp(char *str)
{ {
uint c; size_t c;
c=strlen(str); c=strlen(str);
while(c && (uchar)str[c-1]<=' ') c--; while(c && (uchar)str[c-1]<=' ') c--;
if(str[c]!=0)
str[c]=0; str[c]=0;
return(str); return(str);
} }
...@@ -250,7 +251,7 @@ char* DLLCALL truncstr(char* str, const char* set) ...@@ -250,7 +251,7 @@ char* DLLCALL truncstr(char* str, const char* set)
char* p; char* p;
p=strpbrk(str,set); p=strpbrk(str,set);
if(p!=NULL) if(p!=NULL && *p!=0)
*p=0; *p=0;
return(p); return(p);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment