mirror of
https://github.com/google/pebble.git
synced 2025-06-24 10:06:16 +00:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
33
third_party/nanopb/tests/fuzztest/flakystream.c
vendored
Normal file
33
third_party/nanopb/tests/fuzztest/flakystream.c
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "flakystream.h"
|
||||
#include <string.h>
|
||||
|
||||
bool flakystream_callback(pb_istream_t *stream, pb_byte_t *buf, size_t count)
|
||||
{
|
||||
flakystream_t *state = stream->state;
|
||||
|
||||
if (state->position + count > state->msglen)
|
||||
{
|
||||
stream->bytes_left = 0;
|
||||
return false;
|
||||
}
|
||||
else if (state->position + count > state->fail_after)
|
||||
{
|
||||
PB_RETURN_ERROR(stream, "flaky error");
|
||||
}
|
||||
|
||||
memcpy(buf, state->buffer + state->position, count);
|
||||
state->position += count;
|
||||
return true;
|
||||
}
|
||||
|
||||
void flakystream_init(flakystream_t *stream, const uint8_t *buffer, size_t msglen, size_t fail_after)
|
||||
{
|
||||
memset(stream, 0, sizeof(*stream));
|
||||
stream->stream.callback = flakystream_callback;
|
||||
stream->stream.bytes_left = SIZE_MAX;
|
||||
stream->stream.state = stream;
|
||||
stream->buffer = buffer;
|
||||
stream->position = 0;
|
||||
stream->msglen = msglen;
|
||||
stream->fail_after = fail_after;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue