Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#6373 closed bug (fixed)

Bluetooth address macros are broken

Reported by: zooey Owned by: oruizdorantes
Priority: normal Milestone: R1
Component: Network & Internet/Bluetooth Version: R1/alpha2
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

The bluetooth.h header defines these bdaddr_t macros:

#define BDADDR_NULL		(&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
#define BDADDR_LOCAL		(&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
#define BDADDR_BROADCAST	(&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})

However, the concept of getting an address of a compound literal is pretty much broken, as compound literals are neither part of the C++ standard (though gcc supports them) and their lifetime is not well-controlled inside of a macro.

As an example:

struct foo {
    bdaddr_t peer;
};

void bar()
{
    foo myfoo;
    if (...)
        myfoo.peer = BDADDR_LOCAL;
    else
        myfoo.peer = BDADDR_NULL;

    // try doing something with myfoo, but the actuall bdaddr_t object will
    // be dead here already, so the data at the address myfoo.peer may have
    // been overwritten
}

Instead, I suggest doing something along the lines of:

extern const bdaddr_t __BDADDR_NULL;
extern const bdaddr_t __BDADDR_LOCAL;
extern const bdaddr_t __BDADDR_BROADCAST;

#define BDADDR_NULL		(&__BDADDR_NULL)
#define BDADDR_LOCAL		(&__BDADDR_LOCAL)
#define BDADDR_BROADCAST	(&__BDADDR_BROADCAST)

and then define these constants somewhere in an implementation file that gets linked by all users of those macros.

Change History (4)

comment:1 Changed 9 years ago by zooey

Resolution: fixed
Status: newclosed

Should be fixed in hrev38213.

comment:2 Changed 9 years ago by oruizdorantes

Hi,

The problem of this solution is that these data needs to be explicitly instantiated in each module using it.

Have you tried declarig them inside the class(bdaddrUtils) as a static member? I wonder if this results in symbol duplication at linking.

Regards.

comment:3 Changed 9 years ago by zooey

Right - thanks for the note.

Reverted hrev38213 and fixed differently in hrev38265.

comment:4 Changed 9 years ago by oruizdorantes

Thank you for your time devoted in this, was in my TODO :)

Note: See TracTickets for help on using tickets.