Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

bad `if` statement in ble_advertising_init() (SDK v15.0)

There's an if statement in `ble_advertising_init` around setting the scan response data which never evaluates false:

uint32_t ble_advertising_init(ble_advertising_t            * const p_advertising,
                              ble_advertising_init_t const * const p_init)
{
    ...

    if (&p_init->srdata != NULL)
    {
        p_advertising->adv_data.scan_rsp_data.p_data = p_advertising->enc_scan_rsp_data;
        p_advertising->adv_data.scan_rsp_data.len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX;

        ret = ble_advdata_encode(&p_init->srdata,
                                  p_advertising->adv_data.scan_rsp_data.p_data,
                                 &p_advertising->adv_data.scan_rsp_data.len);
        VERIFY_SUCCESS(ret);
    }
    else
    {
        p_advertising->adv_data.scan_rsp_data.p_data = NULL;
        p_advertising->adv_data.scan_rsp_data.len    = 0;
    }
    
    ...
}

The comparison of `&p_init->sr_data != NULL` will never evaluate false since sr_data is a concrete struct (not struct pointer!) within ble_advertising_init_t and the address of the struct member is part of the comparison.  With this statement I'd expect sr_data to be of type `ble_advdata_t*` and the `&` removed from the comparison

Related