Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setHasFlags() correctly handles PB repeated fields #491

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions src/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,18 +697,47 @@ static void setHasFlags(const pb_msgdesc_t* fields, void* s)
// Not implemented for extension fields
assert(PB_LTYPE(iter.type) != PB_LTYPE_EXTENSION);

if (PB_HTYPE(iter.type) == PB_HTYPE_OPTIONAL && iter.pSize)
switch (PB_HTYPE(iter.type))
{
*reinterpret_cast<char*>(iter.pSize) = true;
}

// Recurse into sub-messages
if (PB_LTYPE(iter.type) == PB_LTYPE_SUBMESSAGE)
{
assert(iter.submsg_desc);
assert(iter.pData);

setHasFlags(iter.submsg_desc, iter.pData);
case PB_HTYPE_OPTIONAL:
{
*reinterpret_cast<bool*>(iter.pSize) = true;

// Recurse into sub-messages
if (PB_LTYPE(iter.type) == PB_LTYPE_SUBMESSAGE)
{
assert(iter.submsg_desc);
assert(iter.pData);

setHasFlags(iter.submsg_desc, iter.pData);
}
break;
}

case PB_HTYPE_REPEATED:
{
// Recurse into sub-messages
if (PB_LTYPE(iter.type) == PB_LTYPE_SUBMESSAGE)
{
assert(iter.submsg_desc);
assert(iter.pData);
assert(iter.pSize);

const pb_size_t array_size = *reinterpret_cast<pb_size_t*>(iter.pSize);
pb_byte_t* item_ptr = reinterpret_cast<pb_byte_t*>(iter.pData);
for (pb_size_t index = 0; index < array_size; ++index)
{
setHasFlags(iter.submsg_desc, item_ptr);
item_ptr += iter.data_size;
}
}
break;
}

default:
// We do not support any other htypes of fields
assert(false);
continue;
}
} while (pb_field_iter_next(&iter));
}
Expand Down