P2P: Split p2p_channels_union() into two functions

The separate p2p_channels_union_inplace() makes the function easier for
static analyzers to see that the result buffer is always initialized.
(CID 74494)

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2014-12-05 22:34:27 +02:00
parent 2f816c212c
commit a6306bcc92
3 changed files with 23 additions and 11 deletions

View file

@ -1366,8 +1366,8 @@ int p2p_prepare_channel(struct p2p_data *p2p, struct p2p_device *dev,
if (go)
p2p_channels_remove_freqs(&p2p->channels, &p2p->no_go_freq);
else if (!force_freq)
p2p_channels_union(&p2p->channels, &p2p->cfg->cli_channels,
&p2p->channels);
p2p_channels_union_inplace(&p2p->channels,
&p2p->cfg->cli_channels);
p2p_channels_dump(p2p, "after go/cli filter/add", &p2p->channels);
p2p_dbg(p2p, "Own preference for operation channel: Operating Class %u Channel %u%s",

View file

@ -613,6 +613,8 @@ int p2p_freq_to_channel(unsigned int freq, u8 *op_class, u8 *channel);
void p2p_channels_intersect(const struct p2p_channels *a,
const struct p2p_channels *b,
struct p2p_channels *res);
void p2p_channels_union_inplace(struct p2p_channels *res,
const struct p2p_channels *b);
void p2p_channels_union(const struct p2p_channels *a,
const struct p2p_channels *b,
struct p2p_channels *res);

View file

@ -193,20 +193,15 @@ static void p2p_op_class_union(struct p2p_reg_class *cl,
/**
* p2p_channels_union - Union of channel lists
* @a: First set of channels
* p2p_channels_union_inplace - Inplace union of channel lists
* @res: Input data and place for returning union of the channel sets
* @b: Second set of channels
* @res: Data structure for returning the union of channels
*/
void p2p_channels_union(const struct p2p_channels *a,
const struct p2p_channels *b,
struct p2p_channels *res)
void p2p_channels_union_inplace(struct p2p_channels *res,
const struct p2p_channels *b)
{
size_t i, j;
if (a != res)
os_memcpy(res, a, sizeof(*res));
for (i = 0; i < res->reg_classes; i++) {
struct p2p_reg_class *cl = &res->reg_class[i];
for (j = 0; j < b->reg_classes; j++) {
@ -236,6 +231,21 @@ void p2p_channels_union(const struct p2p_channels *a,
}
/**
* p2p_channels_union - Union of channel lists
* @a: First set of channels
* @b: Second set of channels
* @res: Data structure for returning the union of channels
*/
void p2p_channels_union(const struct p2p_channels *a,
const struct p2p_channels *b,
struct p2p_channels *res)
{
os_memcpy(res, a, sizeof(*res));
p2p_channels_union_inplace(res, b);
}
void p2p_channels_remove_freqs(struct p2p_channels *chan,
const struct wpa_freq_range_list *list)
{