@@ -211,28 +211,27 @@ static unsigned int hex_char_to_number(uint8_t x)
*/
static size_t mod_strcspn(const char *string, const char *reject)
{
- const char *pr;
- int i;
+ const char *ps, *pr;
if (!string)
return 0;
- for (i = 0; string[i]; i++) {
- if (string[i] == '/' && string[i+1] == '*') {
- i += 2;
- while (string[i] && (string[i] != '*' || string[i+1] != '/'))
- i++;
- i++;
- } else if (string[i] == '/' && string[i+1] == '/') {
- i += 2;
- while (string[i] && string[i] != '\n')
- i++;
+ for (ps = string; *ps; ps++) {
+ if (*ps == '/' && *(ps+1) == '*') {
+ ps += 2;
+ while (*ps && (*ps != '*' || *(ps+1) != '/'))
+ ps++;
+ ps++;
+ } else if (*ps == '/' && *(ps+1) == '/') {
+ ps += 2;
+ while (*ps && *ps != '\n')
+ ps++;
} else if (reject) {
- for (pr = reject; *pr && *pr != string[i]; pr++);
+ for (pr = reject; *pr && *pr != *ps; pr++);
if (*pr)
break;
}
}
- return i;
+ return (ps - string);
}
static uint32_t color_string_to_rgba(const char *p, int len)
Incrementing pointer *ps once is faster than computing string[i] for each time we need it. Bug fix: For the remote possibility of a crazy-long comment section that overflows int, this fix can also return a value larger than sizeof(int). Signed-off-by: Jose Da Silva <digital@joescat.com> --- libavcodec/xpmdec.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) -- 2.30.1