From: <and...@us...> - 2013-12-11 20:35:27
|
Revision: 12853 http://sourceforge.net/p/plplot/code/12853 Author: andrewross Date: 2013-12-11 20:35:24 +0000 (Wed, 11 Dec 2013) Log Message: ----------- Alternative implementation of remove_characters which avoids the valgrind warnings when the code is compiled with -O3. Modified Paths: -------------- trunk/src/pllegend.c Modified: trunk/src/pllegend.c =================================================================== --- trunk/src/pllegend.c 2013-12-11 12:06:41 UTC (rev 12852) +++ trunk/src/pllegend.c 2013-12-11 20:35:24 UTC (rev 12853) @@ -933,16 +933,20 @@ static void remove_characters( char *string, const char *characters ) { - size_t length = strlen( string ); - size_t prefix_length = strcspn( string, characters ); - if ( prefix_length < length ) + char *src, *dst; + const char *ptr; + for(src=dst=string; *src != '\0'; src++) { - // Remove first matching character by shifting tail of string - // (including null-terminator) down by one. - memmove( string + prefix_length, string + prefix_length + 1, length - prefix_length ); - // Recurse to remove any remaining specified characters. - remove_characters( string, characters ); + ptr = characters; + while ( (*ptr != '\0') && (*src != *ptr) ) + ptr++; + if (*src != *ptr) + { + *dst = *src; + dst++; + } } + *dst = '\0'; } //-------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |