Make field decoders return false for unsupported pointer fields.

git-svn-id: https://svn.kapsi.fi/jpa/nanopb-dev@1082 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
Michael Poole
2011-12-20 03:38:48 +00:00
committed by Petteri Aimonen
parent c66c6b43c4
commit f7c8dd81d4
2 changed files with 18 additions and 8 deletions

View File

@@ -590,9 +590,9 @@ bool checkreturn pb_dec_bytes(pb_istream_t *stream, const pb_field_t *field, voi
if (x->size > field->data_size)
return false;
#ifdef MALLOC_HEADER
if (PB_POINTER(field->type))
{
#ifdef MALLOC_HEADER
pb_bytes_t *x2 = (pb_bytes_t*)dest;
if (x2->alloced < x2->size)
@@ -605,8 +605,10 @@ bool checkreturn pb_dec_bytes(pb_istream_t *stream, const pb_field_t *field, voi
}
return pb_read(stream, x2->bytes, x2->size);
}
#else
return false;
#endif
}
return pb_read(stream, x->bytes, x->size);
}
@@ -621,17 +623,19 @@ bool checkreturn pb_dec_string(pb_istream_t *stream, const pb_field_t *field, vo
if (size > field->data_size - 1)
return false;
#ifdef MALLOC_HEADER
if (PB_POINTER(field->type))
{
#ifdef MALLOC_HEADER
uint8_t *string = (uint8_t*)realloc(*(uint8_t**)dest, size + 1);
if (!string)
return false;
*(uint8_t**)dest = string;
dest = string;
}
#else
return false;
#endif
}
status = pb_read(stream, (uint8_t*)dest, size);
*((uint8_t*)dest + size) = 0;
@@ -652,9 +656,9 @@ bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field
msg = (const pb_message_t*)field->ptr;
#ifdef MALLOC_HEADER
if (PB_POINTER(field->type))
{
#ifdef MALLOC_HEADER
if (*(void**)dest == NULL)
{
void *object = malloc(msg->size);
@@ -665,8 +669,10 @@ bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field
} else {
dest = *(void**)dest;
}
}
#else
return false;
#endif
}
status = pb_decode(&substream, msg, dest);
stream->state = substream.state;