- if (0 == val.size) {
- if (reccur >= *recsz) {
- *recsz += MANDOC_SLOP;
- *recs = mandoc_realloc(*recs,
- *recsz * sizeof(recno_t));
- }
- (*recs)[(int)reccur] = *maxrec;
- reccur++;
- continue;
- }
+ cp = val.data;
+
+ /* Deleted records are zero-sized. Skip them. */
+
+ if (0 == val.size)
+ goto cont;
+
+ /*
+ * Make sure we're sane.
+ * Read past our mdoc/man/cat type to the next string,
+ * then make sure it's bounded by a NUL.
+ * Failing any of these, we go into our error handler.
+ */
+
+ if (NULL == (fn = memchr(cp, '\0', val.size)))
+ break;
+ if (++fn - cp >= (int)val.size)
+ break;
+ if (NULL == memchr(fn, '\0', val.size - (fn - cp)))
+ break;
+
+ /*
+ * Search for the file in those we care about.
+ * XXX: build this into a tree. Too slow.
+ */