// Fuzz target for the line scanner: a refused line stays refused when text is
// added at its end, and a file of one line gives one problem exactly when the
// line is refused.
#include "lint.h"
#include "platform.h"
#include <stdint.h>
#include <string.h>
static const LintRules none;
static char longer[LINT_LINE_MAX + 2];
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
static void count(void *state, size_t line, const char *what)
{
(void)line;
(void)what;
++*(size_t *)state;
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
if (size > LINT_LINE_MAX) return 0;
const char *what = lint_line(&none, (const char *)data, size);
if (what != nullptr) {
memcpy(longer, data, size);
longer[size] = 'x';
ensure(lint_line(&none, longer, size + 1) != nullptr);
}
bool one_line = memchr(data, '\n', size) == nullptr && memchr(data, '\0', size < LINT_BINARY_PROBE ? size : LINT_BINARY_PROBE) == nullptr;
if (one_line && size > 0) {
size_t problems = 0;
[[maybe_unused]] size_t n = lint_text(&none, false, (const char *)data, size, count, &problems);
ensure(n == problems && n == (what != nullptr ? 1u : 0u));
}
return 0;
}