@@ -213,22 +213,24 @@ static size_t mod_strcspn(const char *string, const char *reject)
{
int i, j;
- for (i = 0; string && string[i]; i++) {
+ if (!string)
+ return 0;
+ for (i = 0; string[i]; i++) {
if (string[i] == '/' && string[i+1] == '*') {
i += 2;
- while ( string && string[i] && (string[i] != '*' || string[i+1] != '/') )
+ while (string[i] && (string[i] != '*' || string[i+1] != '/'))
i++;
i++;
} else if (string[i] == '/' && string[i+1] == '/') {
i += 2;
- while ( string && string[i] && string[i] != '\n' )
+ while (string[i] && string[i] != '\n')
i++;
- } else {
- for (j = 0; reject && reject[j]; j++) {
+ } else if (reject) {
+ for (j = 0; reject[j]; j++) {
if (string[i] == reject[j])
break;
}
- if (reject && reject[j])
+ if (reject[j])
break;
}
}
Test string==0 once before looping. This avoids testing 'string!=0' i times inside the for i loop, (plus more checks for comments). Test reject==0 once before looping. This avoids testing 'reject!=0' i*[strlen(reject)+1] times inside the for j loop string. Signed-off-by: Jose Da Silva <digital@joescat.com> --- libavcodec/xpmdec.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) -- 2.30.1