XBM loader: Correct load2() result when no header is found

Also require that the header is found within the first 30 lines in the
file.
Otherwise we may waste some time parsing large C files.
This commit is contained in:
Kim Woelders 2022-01-07 10:33:07 +01:00
parent b123cb7674
commit 04b8c35e17
1 changed files with 7 additions and 3 deletions

View File

@ -87,7 +87,7 @@ load2(ImlibImage * im, int load_data)
void *fdata;
char buf[4096], tok1[1024], tok2[1024];
DATA32 *ptr, pixel;
int i, x, y, bit;
int i, x, y, bit, nl;
const char *s;
int header, val, nlen;
@ -113,7 +113,7 @@ load2(ImlibImage * im, int load_data)
x = y = 0;
header = 1;
for (;;)
for (nl = 0;; nl++)
{
s = mm_gets(buf, sizeof(buf));
if (!s)
@ -165,6 +165,9 @@ load2(ImlibImage * im, int load_data)
}
else
{
/* Quit if we don't have the header in N lines */
if (nl >= 30)
break;
continue;
}
}
@ -205,7 +208,8 @@ load2(ImlibImage * im, int load_data)
}
done:
rc = LOAD_SUCCESS;
if (!header)
rc = LOAD_SUCCESS;
quit:
if (rc <= 0)