Пример #1
0
static int read_double(readstat_por_ctx_t *ctx, double *out_double) {
    size_t bytes_read = 0;
    if (ctx->buf_used == 0) {
        bytes_read = read_bytes(ctx, ctx->buf, 100);
        if (bytes_read == -1) {
            return -1;
        }
        ctx->buf_used = bytes_read;
        ctx->buf_pos = 0;
    }
    if (ctx->buf_used - ctx->buf_pos < 40) {
        memcpy(ctx->buf, &ctx->buf[ctx->buf_pos], ctx->buf_used - ctx->buf_pos);
        ctx->buf_used -= ctx->buf_pos;
        ctx->buf_pos = 0;
        bytes_read = read_bytes(ctx, &ctx->buf[ctx->buf_used], sizeof(ctx->buf)-ctx->buf_used);
        if (bytes_read == -1) {
            return -1;
        }
        ctx->buf_used += bytes_read;
    }
    char utf8_buffer[300];
    size_t len = utf8_encode(ctx->buf + ctx->buf_pos, ctx->buf_used - ctx->buf_pos, utf8_buffer, sizeof(utf8_buffer), ctx->lookup);

    if (utf8_buffer[0] == 'Z')
        return 1;

    double value;
    bytes_read = readstat_por_parse_double(utf8_buffer, len, &value, ctx->error_handler, ctx->user_ctx);
    if (bytes_read == -1) {
        return -1;
    }

    ctx->buf_pos += bytes_read;

    if (out_double) {
        *out_double = value;
    }
//    printf("Read double: %lf\n", value);
    return 0;
}
Пример #2
0
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
    readstat_por_parse_double((const char *)Data, Size, NULL, NULL, NULL);
    return 0;
}