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

Return the actual default partition in dds_qget_partition() whenever possible #1824

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/core/ddsc/src/dds_qos.c
Expand Up @@ -618,8 +618,20 @@ bool dds_qget_partition (const dds_qos_t * __restrict qos, uint32_t *n, char ***
*n = qos->partition.n;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the behaviour that, for an entity created with an empty set of partitions:

dds_qget_partition (q, &nA, NULL);
dds_qget_partition (q, &nB, &ps);
assert (nA == nB);

will fail.

if (ps)
{
if (qos->partition.n == 0)
*ps = NULL;
if (qos->partition.n == 0) {
/* This is the default partition.
* Only when the argument n is non-null, we'll
* actually return the default partition (i.e.,
* the empty string "").
* */
if (n) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 615 & 616 ensure (ps ≠ NULL) ⇒ (n ≠ NULL), so we are certain to never end up in the else case. I think the comment that says "this is the default partition" might better be rephrased as "this implies the default partition", then the remainder of the comment, the if (n) and the else branch can be thrown out.

*n = 1;
*ps = dds_alloc (sizeof (char*));
(*ps)[0] = dds_string_dup ("");
} else {
*ps = NULL;
}
}
else
{
*ps = dds_alloc (sizeof (char*) * qos->partition.n);
Expand Down