Skip to content

Commit

Permalink
pdfext: do not use non-POSIX memrchr()
Browse files Browse the repository at this point in the history
Reported by Dirk-Wilhelm Peters <peters@schwertfisch.de>.
  • Loading branch information
aligrudi committed Apr 19, 2018
1 parent 90d1d12 commit 1e7dc3a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pdfext.c
Expand Up @@ -174,13 +174,20 @@ int pdf_lval(char *pdf, int len, int pos, int idx)
return -1;
}

void *memrchr(void *m, int c, long n);
static void *my_memrchr(void *m, int c, long n)
{
int i;
for (i = 0; i < n; i++)
if (*(unsigned char *) (m + n - 1 - i) == c)
return m + n - 1 - i;
return NULL;
}

static int prevline(char *pdf, int len, int off)
{
char *nl = memrchr(pdf, '\n', off);
char *nl = my_memrchr(pdf, '\n', off);
if (nl && nl > pdf) {
char *nl2 = memrchr(pdf, '\n', nl - pdf -1);
char *nl2 = my_memrchr(pdf, '\n', nl - pdf - 1);
if (nl2)
return nl2 - pdf + 1;
}
Expand Down

0 comments on commit 1e7dc3a

Please sign in to comment.