Commit dcdf7a64 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

config_StringEscape: iterate through string twice rather than 3 times

parent 87ea4084
......@@ -451,32 +451,23 @@ char *config_StringUnescape( char *psz_string )
return psz_string;
}
char *config_StringEscape( const char *psz_string )
char *config_StringEscape( const char *str )
{
char *psz_return;
char *psz_dst;
int i_escape;
size_t length = 0;
if( !psz_string )
if( str == NULL )
return NULL;
i_escape = 0;
for( const char *p = psz_string; *p; p++ )
{
if( IsEscapeNeeded( *p ) )
i_escape++;
}
for( const char *p = str; *p; p++ )
length += IsEscapeNeeded( *p ) ? 2 : 1;
psz_return = psz_dst = malloc( strlen( psz_string ) + i_escape + 1 );
for( const char *p = psz_string; *p; p++ )
char *ret = xmalloc( length + 1 ), *dst = ret;
for( const char *p = str; *p; p++ )
{
if( IsEscapeNeeded( *p ) )
*psz_dst++ = '\\';
*psz_dst++ = *p;
*dst++ = '\\';
*dst++ = *p;
}
*psz_dst = '\0';
return psz_return;
*dst = '\0';;
return ret;
}
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