mirror of
https://github.com/firebase/nanopb
synced 2026-11-09 22:25:59 +05:45
Fix clang undefined behavior sanitizer errors.
Signed and unsigned integer overflows, no actual consequences but clean up the errors. Backport of commits6801500e23and69e02afb6e.
This commit is contained in:
1 parent
4c961421e1
commit
50e366d2c3
3 files changed
+15
-8
No files matched your search
+11
-2
@@ -11,8 +11,17 @@ bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_field_t *fields, void *
|
||||
iter->pos = fields;
|
||||
iter->required_field_index = 0;
|
||||
iter->dest_struct = dest_struct;
|
||||
iter->pData = (char*)dest_struct + iter->pos->data_offset;
|
||||
iter->pSize = (char*)iter->pData + iter->pos->size_offset;
|
||||
|
||||
if (!dest_struct)
|
||||
{
|
||||
iter->pData = NULL;
|
||||
iter->pSize = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter->pData = (char*)dest_struct + iter->pos->data_offset;
|
||||
iter->pSize = (char*)iter->pData + iter->pos->size_offset;
|
||||
}
|
||||
|
||||
return (iter->pos->tag != 0);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1222,7 +1222,7 @@ static void pb_release_single_field(const pb_field_iter_t *iter)
|
||||
|
||||
if (pItem)
|
||||
{
|
||||
while (count--)
|
||||
for (; count > 0; count--)
|
||||
{
|
||||
pb_release((const pb_field_t*)iter->pos->ptr, pItem);
|
||||
pItem = (char*)pItem + iter->pos->data_size;
|
||||
@@ -1239,7 +1239,7 @@ static void pb_release_single_field(const pb_field_iter_t *iter)
|
||||
/* Release entries in repeated string or bytes array */
|
||||
void **pItem = *(void***)iter->pData;
|
||||
pb_size_t count = *(pb_size_t*)iter->pSize;
|
||||
while (count--)
|
||||
for (; count > 0; count--)
|
||||
{
|
||||
pb_free(*pItem);
|
||||
*pItem++ = NULL;
|
||||
|
||||
+2
-4
@@ -852,7 +852,6 @@ static bool checkreturn pb_enc_fixed32(pb_ostream_t *stream, const pb_field_t *f
|
||||
static bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src)
|
||||
{
|
||||
const pb_bytes_array_t *bytes = NULL;
|
||||
size_t allocsize;
|
||||
|
||||
bytes = (const pb_bytes_array_t*)src;
|
||||
|
||||
@@ -862,9 +861,8 @@ static bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *fie
|
||||
return pb_encode_string(stream, NULL, 0);
|
||||
}
|
||||
|
||||
allocsize = PB_BYTES_ARRAY_T_ALLOCSIZE(bytes->size);
|
||||
if (allocsize < bytes->size ||
|
||||
(PB_ATYPE(field->type) == PB_ATYPE_STATIC && allocsize > field->data_size))
|
||||
if (PB_ATYPE(field->type) == PB_ATYPE_STATIC &&
|
||||
bytes->size > field->data_size - offsetof(pb_bytes_array_t, bytes))
|
||||
{
|
||||
PB_RETURN_ERROR(stream, "bytes size exceeded");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user