Commit 6c906123 authored by rswindell's avatar rswindell
Browse files

truncsp() and truncnl() no-longer 0-terminate string if there's nothing to

truncate (e.g. avoids segfaults w/call of truncsp("")).
parent 0a2a5c99
......@@ -422,11 +422,12 @@ clock_t DLLCALL msclock(void)
/****************************************************************************/
char* DLLCALL truncsp(char* str)
{
unsigned c;
size_t i,len;
c=strlen(str);
while(c && (str[c-1]==' ' || str[c-1]=='\t' || str[c-1]=='\r' || str[c-1]=='\n')) c--;
str[c]=0;
i=len=strlen(str);
while(i && (str[i-1]==' ' || str[i-1]=='\t' || str[i-1]=='\r' || str[i-1]=='\n')) i--;
if(i!=len)
str[i]=0; /* truncate */
return(str);
}
......@@ -436,11 +437,12 @@ char* DLLCALL truncsp(char* str)
/****************************************************************************/
char* DLLCALL truncnl(char* str)
{
unsigned c;
size_t i,len;
c=strlen(str);
while(c && (str[c-1]=='\r' || str[c-1]=='\n')) c--;
str[c]=0;
i=len=strlen(str);
while(i && (str[i-1]=='\r' || str[i-1]=='\n')) i--;
if(i!=len)
str[i]=0; /* truncate */
return(str);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment