for (uint32_t i = 0; i < bta_ag_local_hf_ind_cfg[0].ind_id; i++)
{
- if (bta_ag_local_hf_ind_cfg[i+1].is_supported == true)
+ if (bta_ag_local_hf_ind_cfg[i+1].is_supported)
{
/* Add ',' from second indicator */
- if (index > 1)
- buffer[index++] = ',';
- sprintf(&buffer[index++], "%d", bta_ag_local_hf_ind_cfg[i+1].ind_id);
+ if (index > 1) buffer[index++] = ',';
+ snprintf(&buffer[index++], 1, "%d",
+ bta_ag_local_hf_ind_cfg[i+1].ind_id);
}
}
#define GATT_CACHE_PREFIX "/data/misc/bluetooth/gatt_cache_"
#define GATT_CACHE_VERSION 2
-static void bta_gattc_generate_cache_file_name(char *buffer, BD_ADDR bda)
+static void bta_gattc_generate_cache_file_name(char *buffer,
+ size_t buffer_len, BD_ADDR bda)
{
- sprintf(buffer, "%s%02x%02x%02x%02x%02x%02x", GATT_CACHE_PREFIX,
+ snprintf(buffer, buffer_len, "%s%02x%02x%02x%02x%02x%02x", GATT_CACHE_PREFIX,
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
}
bool bta_gattc_cache_load(tBTA_GATTC_CLCB *p_clcb)
{
char fname[255] = {0};
- bta_gattc_generate_cache_file_name(fname, p_clcb->p_srcb->server_bda);
+ bta_gattc_generate_cache_file_name(fname, sizeof(fname), p_clcb->p_srcb->server_bda);
FILE *fd = fopen(fname, "rb");
if (!fd) {
tBTA_GATTC_NV_ATTR *attr)
{
char fname[255] = {0};
- bta_gattc_generate_cache_file_name(fname, server_bda);
+ bta_gattc_generate_cache_file_name(fname, sizeof(fname), server_bda);
FILE *fd = fopen(fname, "wb");
if (!fd) {
{
BTIF_TRACE_DEBUG("%s", __func__);
char fname[255] = {0};
- bta_gattc_generate_cache_file_name(fname, server_bda);
+ bta_gattc_generate_cache_file_name(fname, sizeof(fname), server_bda);
unlink(fname);
}
#endif /* BTA_GATT_INCLUDED */
static void fcchan_data_cbk(uint16_t chan, BD_ADDR bd_addr, BT_HDR *p_buf);
-extern void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str);
+extern void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str, size_t str_len);
static inline void logu(const char* title, const uint8_t * p_uuid)
{
char uuids[128];
- uuid_to_string_legacy((bt_uuid_t*)p_uuid, uuids);
+ uuid_to_string_legacy((bt_uuid_t*)p_uuid, uuids, sizeof(uuids));
APPL_TRACE_DEBUG("%s: %s", title, uuids);
}
return NULL;
const uint8_t *ptr = addr->address;
- sprintf(string, "%02x:%02x:%02x:%02x:%02x:%02x",
- ptr[0], ptr[1], ptr[2],
- ptr[3], ptr[4], ptr[5]);
+ snprintf(string, size, "%02x:%02x:%02x:%02x:%02x:%02x",
+ ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
return string;
}
assert(uuid_string != NULL);
char *string = uuid_string->string;
+ char *end = string + UUID_WELL_FORMED_STRING_LEN_WITH_NULL;
+ // XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX
for (int i = 0; i < 4; i++) {
- string += sprintf(string, "%02x", uuid->uu[i]);
+ string += snprintf(string, end - string, "%02x", uuid->uu[i]);
}
- string += sprintf(string, "-");
+ *string = '-';
+ ++string;
for (int i = 4; i < 6; i++) {
- string += sprintf(string, "%02x", uuid->uu[i]);
+ string += snprintf(string, end - string, "%02x", uuid->uu[i]);
}
- string += sprintf(string, "-");
+ *string = '-';
+ ++string;
for (int i = 6; i < 8; i++) {
- string += sprintf(string, "%02x", uuid->uu[i]);
+ string += snprintf(string, end - string, "%02x", uuid->uu[i]);
}
- string += sprintf(string, "-");
+ *string = '-';
+ ++string;
for (int i = 8; i < 10; i++) {
- string += sprintf(string, "%02x", uuid->uu[i]);
+ string += snprintf(string, end - string, "%02x", uuid->uu[i]);
}
- string += sprintf(string, "-");
+ *string = '-';
+ ++string;
for (int i = 10; i < 16; i++) {
- string += sprintf(string, "%02x", uuid->uu[i]);
+ string += snprintf(string, end - string, "%02x", uuid->uu[i]);
}
}
unsigned idx = 0;
bdstr_t bdstr;
- sprintf(bdstr, "%02x:%02x:%02x:%02x:%02x:%02x",
+ snprintf(bdstr, sizeof(bdstr), "%02x:%02x:%02x:%02x:%02x:%02x",
remote_bda[0], remote_bda[1], remote_bda[2],
remote_bda[3], remote_bda[4], remote_bda[5]);
UNUSED(app_id);
bdstr_t bdstr;
- sprintf(bdstr, "%02x:%02x:%02x:%02x:%02x:%02x",
+ snprintf(bdstr, sizeof(bdstr), "%02x:%02x:%02x:%02x:%02x:%02x",
remote_bda[0], remote_bda[1], remote_bda[2],
remote_bda[3], remote_bda[4], remote_bda[5]);
UNUSED(app_id);
bdstr_t bdstr;
- sprintf(bdstr, "%02x:%02x:%02x:%02x:%02x:%02x",
+ snprintf(bdstr, sizeof(bdstr), "%02x:%02x:%02x:%02x:%02x:%02x",
remote_bda[0], remote_bda[1], remote_bda[2],
remote_bda[3], remote_bda[4], remote_bda[5]);
btif_config_remove(bdstr, "HidReport");
int ascii_2_hex (const char *p_ascii, int len, uint8_t *p_hex);
-extern "C" void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str);
+extern "C" void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str, size_t str_len);
#endif /* BTIF_UTIL_H */
for (i=0; i < p_data->disc_res.num_uuids; i++)
{
char temp[256];
- uuid_to_string_legacy((bt_uuid_t*)(p_data->disc_res.p_uuid_list + (i*MAX_UUID_SIZE)), temp);
+ uuid_to_string_legacy((bt_uuid_t*)(p_data->disc_res.p_uuid_list + (i*MAX_UUID_SIZE)), temp,
+ sizeof(temp));
LOG_INFO(LOG_TAG, "%s index:%d uuid:%s", __func__, i, temp);
}
}
j--;
}
- uuid_to_string_legacy(&uuid, temp);
+ uuid_to_string_legacy(&uuid, temp, sizeof(temp));
LOG_INFO(LOG_TAG, "%s uuid:%s", __func__, temp);
bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr);
fclose(fp);
}
BTIF_TRACE_DEBUG("----%s: true", __func__);
- sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x",
+ snprintf(t, sizeof(t), "%02x:%02x:%02x:%02x:%02x:%02x",
oob_cb.bdaddr[0], oob_cb.bdaddr[1], oob_cb.bdaddr[2],
oob_cb.bdaddr[3], oob_cb.bdaddr[4], oob_cb.bdaddr[5]);
BTIF_TRACE_DEBUG("----%s: peer_bdaddr = %s", __func__, t);
- sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
- p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
- p_c[8], p_c[9], p_c[10], p_c[11], p_c[12], p_c[13], p_c[14], p_c[15]);
+ snprintf(t, sizeof(t), "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
+ p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
+ p_c[8], p_c[9], p_c[10], p_c[11], p_c[12], p_c[13], p_c[14], p_c[15]);
BTIF_TRACE_DEBUG("----%s: c = %s", __func__, t);
- sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
- p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
- p_r[8], p_r[9], p_r[10], p_r[11], p_r[12], p_r[13], p_r[14], p_r[15]);
+ snprintf(t, sizeof(t), "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
+ p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
+ p_r[8], p_r[9], p_r[10], p_r[11], p_r[12], p_r[13], p_r[14], p_r[15]);
BTIF_TRACE_DEBUG("----%s: r = %s", __func__, t);
bdcpy(bt_bd_addr.address, bd_addr);
btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING,
* Callback functions
*******************************************************************************/
-static char * format_uuid(tBT_UUID bt_uuid, char *str_buf)
+static char * format_uuid(tBT_UUID bt_uuid, char *str_buf, size_t buf_size)
{
- int x = 0;
+
if (bt_uuid.len == LEN_UUID_16)
{
- sprintf(str_buf, "0x%04x", bt_uuid.uu.uuid16);
+ snprintf(str_buf, buf_size, "0x%04x", bt_uuid.uu.uuid16);
}
else if (bt_uuid.len == LEN_UUID_128)
{
- x += sprintf(&str_buf[x], "%02x%02x%02x%02x-%02x%02x-%02x%02x",
+ int x = snprintf(str_buf, buf_size,
+ "%02x%02x%02x%02x-%02x%02x-%02x%02x",
bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14],
bt_uuid.uu.uuid128[13], bt_uuid.uu.uuid128[12],
bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10],
bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]);
- sprintf(&str_buf[x], "%02x%02x-%02x%02x%02x%02x%02x%02x",
+ snprintf(&str_buf[x], buf_size - x,
+ "%02x%02x-%02x%02x%02x%02x%02x%02x",
bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6],
bt_uuid.uu.uuid128[5], bt_uuid.uu.uuid128[4],
bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2],
bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]);
}
- else
- sprintf(str_buf, "Unknown (len=%d)", bt_uuid.len);
+ else {
+ snprintf(str_buf, buf_size, "Unknown (len=%d)", bt_uuid.len);
+ }
return str_buf;
}
LOG_DEBUG(LOG_TAG, " Attribute handle: 0x%04x (%d)", p_data->handle, p_data->handle);
if (disc_type != GATT_DISC_CHAR_DSCPT) {
- LOG_DEBUG(LOG_TAG, " Attribute type: %s", format_uuid(p_data->type, str_buf));
+ LOG_DEBUG(LOG_TAG, " Attribute type: %s", format_uuid(p_data->type, str_buf, sizeof(str_buf)));
}
switch (disc_type)
p_data->handle, p_data->value.group_value.e_handle,
p_data->handle, p_data->value.group_value.e_handle);
LOG_DEBUG(LOG_TAG, " Service UUID: %s",
- format_uuid(p_data->value.group_value.service_type, str_buf));
+ format_uuid(p_data->value.group_value.service_type, str_buf, sizeof(str_buf)));
break;
case GATT_DISC_SRVC_BY_UUID:
p_data->value.incl_service.s_handle, p_data->value.incl_service.e_handle,
p_data->value.incl_service.s_handle, p_data->value.incl_service.e_handle);
LOG_DEBUG(LOG_TAG, " Service UUID: %s",
- format_uuid(p_data->value.incl_service.service_type, str_buf));
+ format_uuid(p_data->value.incl_service.service_type, str_buf, sizeof(str_buf)));
break;
case GATT_DISC_CHAR:
LOG_DEBUG(LOG_TAG, " Properties: 0x%02x",
p_data->value.dclr_value.char_prop);
LOG_DEBUG(LOG_TAG, " Characteristic UUID: %s",
- format_uuid(p_data->value.dclr_value.char_uuid, str_buf));
+ format_uuid(p_data->value.dclr_value.char_uuid, str_buf, sizeof(str_buf)));
break;
case GATT_DISC_CHAR_DSCPT:
- LOG_DEBUG(LOG_TAG, " Descriptor UUID: %s", format_uuid(p_data->type, str_buf));
+ LOG_DEBUG(LOG_TAG, " Descriptor UUID: %s", format_uuid(p_data->type, str_buf, sizeof(str_buf)));
break;
}
LOG_DEBUG(LOG_TAG, "%s: DISCOVER (%s), conn_id=%d, uuid=%s, handles=0x%04x-0x%04x",
__func__, disc_name[params->u1], test_cb.conn_id,
- format_uuid(param.service, buf), params->u2, params->u3);
+ format_uuid(param.service, buf, sizeof(buf)), params->u2, params->u3);
GATTC_Discover(test_cb.conn_id, params->u1, ¶m);
break;
}
tBTA_AG_RES_DATA ag_res;
/* Format the response */
- sprintf (ag_res.str, "0,0,\"%.16s\"", cops);
+ snprintf (ag_res.str, sizeof(ag_res.str), "0,0,\"%.16s\"", cops);
ag_res.ok_flag = BTA_AG_OK_DONE;
BTA_AgResult (btif_hf_cb[idx].handle, BTA_AG_COPS_RES, &ag_res);
/* per the errata 2043, call=1 implies atleast one call is in progress (active/held)
** https://www.bluetooth.org/errata/errata_view.cfm?errata_id=2043
**/
- sprintf (ag_res.str, "%d,%d,%d,%d,%d,%d,%d",
- (num_active + num_held) ? 1 : 0, /* Call state */
- callstate_to_callsetup(call_setup_state), /* Callsetup state */
- svc, /* network service */
- signal, /* Signal strength */
- roam, /* Roaming indicator */
- batt_chg, /* Battery level */
- ((num_held == 0) ? 0 : ((num_active == 0) ? 2 : 1))); /* Call held */
+ snprintf (ag_res.str, sizeof(ag_res.str), "%d,%d,%d,%d,%d,%d,%d",
+ (num_active + num_held) ? 1 : 0, /* Call state */
+ callstate_to_callsetup(call_setup_state), /* Callsetup state */
+ svc, /* network service */
+ signal, /* Signal strength */
+ roam, /* Roaming indicator */
+ batt_chg, /* Battery level */
+ ((num_held == 0) ? 0 : ((num_active == 0) ? 2 : 1))); /* Call held */
BTA_AgResult (btif_hf_cb[idx].handle, BTA_AG_CIND_RES, &ag_res);
if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX))
{
tBTA_AG_RES_DATA ag_res;
- int xx;
memset (&ag_res, 0, sizeof (ag_res));
{
BTIF_TRACE_EVENT("clcc_response: [%d] dir %d state %d mode %d number = %s type = %d",
index, dir, state, mode, number, type);
- xx = sprintf (ag_res.str, "%d,%d,%d,%d,%d",
- index, dir, state, mode, mpty);
+ int xx = snprintf (ag_res.str, sizeof(ag_res.str), "%d,%d,%d,%d,%d",
+ index, dir, state, mode, mpty);
if (number)
{
+ size_t rem_bytes = sizeof(ag_res.str) - xx;
if ((type == BTHF_CALL_ADDRTYPE_INTERNATIONAL) && (*number != '+'))
- sprintf (&ag_res.str[xx], ",\"+%s\",%d", number, type);
+ snprintf (&ag_res.str[xx], rem_bytes, ",\"+%s\",%d", number, type);
else
- sprintf (&ag_res.str[xx], ",\"%s\",%d", number, type);
+ snprintf (&ag_res.str[xx], rem_bytes, ",\"%s\",%d", number, type);
}
}
BTA_AgResult (btif_hf_cb[idx].handle, BTA_AG_CLCC_RES, &ag_res);
{
int xx = 0;
if ((type == BTHF_CALL_ADDRTYPE_INTERNATIONAL) && (*number != '+'))
- xx = sprintf (ag_res.str, "\"+%s\"", number);
+ xx = snprintf (ag_res.str, sizeof(ag_res.str), "\"+%s\"", number);
else
- xx = sprintf (ag_res.str, "\"%s\"", number);
+ xx = snprintf (ag_res.str, sizeof(ag_res.str), "\"%s\"", number);
ag_res.num = type;
if (res == BTA_AG_CALL_WAIT_RES)
- sprintf(&ag_res.str[xx], ",%d", type);
+ snprintf(&ag_res.str[xx], sizeof(ag_res.str) - xx, ",%d", type);
}
break;
case BTHF_CALL_STATE_DIALING:
BTIF_TRACE_DEBUG("%s", __func__);
btif_hh_device_t *p_dev;
char bd_str[18];
- sprintf(bd_str, "%02X:%02X:%02X:%02X:%02X:%02X",
- bd_addr->address[0], bd_addr->address[1], bd_addr->address[2], bd_addr->address[3],
- bd_addr->address[4], bd_addr->address[5]);
+ snprintf(bd_str, sizeof(bd_str), "%02X:%02X:%02X:%02X:%02X:%02X",
+ bd_addr->address[0], bd_addr->address[1], bd_addr->address[2], bd_addr->address[3],
+ bd_addr->address[4], bd_addr->address[5]);
p_dev = btif_hh_find_dev_by_bda(bd_addr);
if ((p_dev != NULL) && (p_dev->dev_status == BTHH_CONN_STATE_CONNECTED)
&& (p_dev->attr_mask & HID_VIRTUAL_CABLE))
CHECK_BTHH_INIT();
dev = btif_hh_find_dev_by_bda(bd_addr);
BTIF_TRACE_DEBUG("Connect _hh");
- sprintf(bda_str, "%02X:%02X:%02X:%02X:%02X:%02X",
- (*bda)[0], (*bda)[1], (*bda)[2], (*bda)[3], (*bda)[4], (*bda)[5]);
+ snprintf(bda_str, sizeof(bda_str), "%02X:%02X:%02X:%02X:%02X:%02X",
+ (*bda)[0], (*bda)[1], (*bda)[2], (*bda)[3], (*bda)[4], (*bda)[5]);
if (dev == NULL && btif_hh_cb.device_num >= BTIF_HH_MAX_HID) {
// No space for more HID device now.
BTIF_TRACE_WARNING("%s: Error, exceeded the maximum supported HID device number %d",
CHECK_BTHH_INIT();
btif_hh_device_t *p_dev;
char bd_str[18];
- sprintf(bd_str, "%02X:%02X:%02X:%02X:%02X:%02X",
- bd_addr->address[0], bd_addr->address[1], bd_addr->address[2], bd_addr->address[3],
- bd_addr->address[4], bd_addr->address[5]);
+ snprintf(bd_str, sizeof(bd_str), "%02X:%02X:%02X:%02X:%02X:%02X",
+ bd_addr->address[0], bd_addr->address[1], bd_addr->address[2],
+ bd_addr->address[3], bd_addr->address[4], bd_addr->address[5]);
if (btif_hh_cb.status == BTIF_HH_DISABLED)
{
BTIF_TRACE_ERROR("%s: Error, HH status = %d", __func__, btif_hh_cb.status);
{
bt_uuid_t *p_uuid = (bt_uuid_t*)prop->val + i;
memset(buf, 0, sizeof(buf));
- uuid_to_string_legacy(p_uuid, buf);
+ uuid_to_string_legacy(p_uuid, buf, sizeof(buf));
strcat(value, buf);
//strcat(value, ";");
strcat(value, " ");
return true;
}
-void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str)
+void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str, size_t str_len)
{
uint32_t uuid0, uuid4;
uint16_t uuid1, uuid2, uuid3, uuid5;
memcpy(&uuid4, &(p_uuid->uu[10]), 4);
memcpy(&uuid5, &(p_uuid->uu[14]), 2);
- sprintf((char *)str, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
- ntohl(uuid0), ntohs(uuid1),
- ntohs(uuid2), ntohs(uuid3),
- ntohl(uuid4), ntohs(uuid5));
+ snprintf(str, str_len, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
+ ntohl(uuid0), ntohs(uuid1),
+ ntohs(uuid2), ntohs(uuid3),
+ ntohl(uuid4), ntohs(uuid5));
return;
}
assert(key != NULL);
char value_str[32] = { 0 };
- sprintf(value_str, "%d", value);
+ snprintf(value_str, sizeof(value_str), "%d", value);
config_set_string(config, section, key, value_str);
}
{
STREAM_TO_ARRAY16(p_uuid_list + yy * LEN_UUID_128, p_uuid_data);
for( xx = 0; xx < LEN_UUID_128; xx++ )
- sprintf(buff + xx*2, "%02X", *(p_uuid_list + yy * LEN_UUID_128 + xx));
+ snprintf(buff + xx*2, sizeof(buff) - xx*2, "%02X",
+ *(p_uuid_list + yy * LEN_UUID_128 + xx));
BTM_TRACE_DEBUG(" 0x%s", buff);
}
}
#include "l2c_int.h"
#if (BT_USE_TRACES == TRUE && BT_TRACE_VERBOSE == FALSE)
-/* needed for sprintf() */
+/* needed for snprintf() */
#include <stdio.h>
#endif
return("???");
#else
- sprintf(btm_cb.state_temp_buffer,"%hhu",state);
+ snprintf(btm_cb.state_temp_buffer, sizeof(btm_cb.state_temp_buffer),
+ "%hhu", state);
return(btm_cb.state_temp_buffer);
#endif
return status;
}
-static void uuid_to_str(const tBT_UUID bt_uuid, char *str_buf)
+static void uuid_to_str(const tBT_UUID bt_uuid, char *str_buf, size_t buf_len)
{
- int x = 0;
-
if (bt_uuid.len == LEN_UUID_16) {
- sprintf(str_buf, "0x%04x", bt_uuid.uu.uuid16);
+ snprintf(str_buf, buf_len, "0x%04x", bt_uuid.uu.uuid16);
} else if (bt_uuid.len == LEN_UUID_32) {
- sprintf(str_buf, "0x%08x", bt_uuid.uu.uuid32);
+ snprintf(str_buf, buf_len, "0x%08x", bt_uuid.uu.uuid32);
} else if (bt_uuid.len == LEN_UUID_128)
{
- x += sprintf(&str_buf[x], "%02x%02x%02x%02x-%02x%02x-%02x%02x-",
+ int x = snprintf(str_buf, buf_len, "%02x%02x%02x%02x-%02x%02x-%02x%02x-",
bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14],
bt_uuid.uu.uuid128[13], bt_uuid.uu.uuid128[12],
bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10],
bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]);
- sprintf(&str_buf[x], "%02x%02x-%02x%02x%02x%02x%02x%02x",
+ snprintf(&str_buf[x], buf_len - x, "%02x%02x-%02x%02x%02x%02x%02x%02x",
bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6],
bt_uuid.uu.uuid128[5], bt_uuid.uu.uuid128[4],
bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2],
bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]);
}
else
- sprintf(str_buf, "Unknown (len=%d)", bt_uuid.len);
+ snprintf(str_buf, buf_len, "Unknown (len=%d)", bt_uuid.len);
}
/*******************************************************************************
}
char uuid_str[37];
- uuid_to_str(p_attr->uuid, uuid_str);
+ uuid_to_str(p_attr->uuid, uuid_str, sizeof(uuid_str));
GATT_TRACE_ERROR("=====> handle = [0x%04x] uuid = [%s] perm=0x%02x ",
p_attr->handle, uuid_str, p_attr->permission);
void gatt_dbg_display_uuid(tBT_UUID bt_uuid)
{
char str_buf[50];
- int x = 0;
if (bt_uuid.len == LEN_UUID_16)
{
- sprintf(str_buf, "0x%04x", bt_uuid.uu.uuid16);
+ snprintf(str_buf, sizeof(str_buf), "0x%04x", bt_uuid.uu.uuid16);
}
else if (bt_uuid.len == LEN_UUID_32)
{
- sprintf(str_buf, "0x%08x", (unsigned int)bt_uuid.uu.uuid32);
+ snprintf(str_buf, sizeof(str_buf), "0x%08x", (unsigned int)bt_uuid.uu.uuid32);
}
else if (bt_uuid.len == LEN_UUID_128)
{
- x += sprintf(&str_buf[x], "0x%02x%02x%02x%02x%02x%02x%02x%02x",
- bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14],
- bt_uuid.uu.uuid128[13], bt_uuid.uu.uuid128[12],
- bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10],
- bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]);
- sprintf(&str_buf[x], "%02x%02x%02x%02x%02x%02x%02x%02x",
- bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6],
- bt_uuid.uu.uuid128[5], bt_uuid.uu.uuid128[4],
- bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2],
- bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]);
+ int x = snprintf(str_buf, sizeof(str_buf),
+ "0x%02x%02x%02x%02x%02x%02x%02x%02x",
+ bt_uuid.uu.uuid128[15], bt_uuid.uu.uuid128[14],
+ bt_uuid.uu.uuid128[13], bt_uuid.uu.uuid128[12],
+ bt_uuid.uu.uuid128[11], bt_uuid.uu.uuid128[10],
+ bt_uuid.uu.uuid128[9], bt_uuid.uu.uuid128[8]);
+ snprintf(&str_buf[x], sizeof(str_buf) - x,
+ "%02x%02x%02x%02x%02x%02x%02x%02x",
+ bt_uuid.uu.uuid128[7], bt_uuid.uu.uuid128[6],
+ bt_uuid.uu.uuid128[5], bt_uuid.uu.uuid128[4],
+ bt_uuid.uu.uuid128[3], bt_uuid.uu.uuid128[2],
+ bt_uuid.uu.uuid128[1], bt_uuid.uu.uuid128[0]);
}
else
strlcpy(str_buf, "Unknown UUID 0", sizeof(str_buf));
if ( (p_ccb->local_cid >= L2CAP_BASE_APPL_CID) && (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) )
{
uint32_t dur = time_get_os_boottime_ms() - p_ccb->fcrb.connect_tick_count;
- char *p_str = (char *)osi_malloc(120);
+ size_t p_str_size = 120;
+ char *p_str = (char *)osi_malloc(p_str_size);
uint16_t i;
uint32_t throughput_avg, ack_delay_avg, ack_q_count_avg;
BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC,
"max_held_acks:%08u, in_cfg.fcr.tx_win_sz:%08u", p_ccb->fcrb.max_held_acks, p_ccb->peer_cfg.fcr.tx_win_sz );
- sprintf(p_str, "Sent Pkts:%08u Bytes:%10u(%06u/sec) RR:%08u REJ:%08u RNR:%08u SREJ:%08u",
+ snprintf(p_str, p_str_size, "Sent Pkts:%08u Bytes:%10u(%06u/sec) RR:%08u REJ:%08u RNR:%08u SREJ:%08u",
p_ccb->fcrb.ertm_pkt_counts[0], p_ccb->fcrb.ertm_byte_counts[0],
(dur >= 10 ? (p_ccb->fcrb.ertm_byte_counts[0] * 100) / (dur / 10) : 0),
p_ccb->fcrb.s_frames_sent[0], p_ccb->fcrb.s_frames_sent[1], p_ccb->fcrb.s_frames_sent[2], p_ccb->fcrb.s_frames_sent[3]);
BT_TRACE(TRACE_CTRL_GENERAL | TRACE_LAYER_GKI | TRACE_ORG_GKI , TRACE_TYPE_GENERIC, "%s", p_str);
- sprintf(p_str, "Rcvd Pkts:%08u Bytes:%10u(%06u/sec) RR:%08u REJ:%08u RNR:%08u SREJ:%08u",
+ snprintf(p_str, p_str_size, "Rcvd Pkts:%08u Bytes:%10u(%06u/sec) RR:%08u REJ:%08u RNR:%08u SREJ:%08u",
p_ccb->fcrb.ertm_pkt_counts[1], p_ccb->fcrb.ertm_byte_counts[1],
(dur >= 10 ? (p_ccb->fcrb.ertm_byte_counts[1] * 100) / (dur / 10) : 0),
p_ccb->fcrb.s_frames_rcvd[0], p_ccb->fcrb.s_frames_rcvd[1], p_ccb->fcrb.s_frames_rcvd[2], p_ccb->fcrb.s_frames_rcvd[3]);
continue;
}
- sprintf(p_str, "[%02u] throughput: %5u, ack_delay avg:%3u, min:%3u, max:%3u, ack_q_count avg:%3u, min:%3u, max:%3u",
+ snprintf(p_str, p_str_size, "[%02u] throughput: %5u, ack_delay avg:%3u, min:%3u, max:%3u, ack_q_count avg:%3u, min:%3u, max:%3u",
i, p_ccb->fcrb.throughput[i],
p_ccb->fcrb.ack_delay_avg[i], p_ccb->fcrb.ack_delay_min[i], p_ccb->fcrb.ack_delay_max[i],
p_ccb->fcrb.ack_q_count_avg[i], p_ccb->fcrb.ack_q_count_min[i], p_ccb->fcrb.ack_q_count_max[i] );
p_ccb->fcrb.throughput_start = timestamp;
- sprintf(str, "[%02u] throughput: %5u, ack_delay avg:%3u, min:%3u, max:%3u, ack_q_count avg:%3u, min:%3u, max:%3u",
+ snprintf(str, sizeof(str), "[%02u] throughput: %5u, ack_delay avg:%3u, min:%3u, max:%3u, ack_q_count avg:%3u, min:%3u, max:%3u",
index, p_ccb->fcrb.throughput[index],
p_ccb->fcrb.ack_delay_avg[index], p_ccb->fcrb.ack_delay_min[index], p_ccb->fcrb.ack_delay_max[index],
p_ccb->fcrb.ack_q_count_avg[index], p_ccb->fcrb.ack_q_count_min[index], p_ccb->fcrb.ack_q_count_max[index] );
for (i = 0, p_pcb = pan_cb.pcb; i < MAX_PAN_CONNS; i++, p_pcb++)
{
- sprintf (buff, "%d state %d, handle %d, src 0x%x, dst 0x%x, BD %x.%x.%x.%x.%x.%x",
+ snprintf (buff, sizeof(buff),
+ "%d state %d, handle %d, src 0x%x, dst 0x%x, BD %x.%x.%x.%x.%x.%x",
i, p_pcb->con_state, p_pcb->handle, p_pcb->src_uuid, p_pcb->dst_uuid,
p_pcb->rem_bda[0], p_pcb->rem_bda[1], p_pcb->rem_bda[2],
p_pcb->rem_bda[3], p_pcb->rem_bda[4], p_pcb->rem_bda[5]);
(attr_type == DATA_ELE_ALT_DESC_TYPE))
{
uint8_t num_array[400];
- uint32_t i;
uint32_t len = (attr_len > 200) ? 200 : attr_len;
num_array[0] ='\0';
- for (i = 0; i < len; i++)
+ for (uint32_t i = 0; i < len; i++)
{
- sprintf((char *)&num_array[i*2],"%02X",(uint8_t)(p_val[i]));
+ snprintf((char *)&num_array[i*2], sizeof(num_array) - i*2,
+ "%02X",(uint8_t)(p_val[i]));
}
SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s",
handle,attr_id,attr_type,attr_len,p_val,num_array);
for (i = 0; i < p_ccb->list_len; i++)
{
- sprintf((char *)&num_array[i*2],"%02X",(uint8_t)(p_ccb->rsp_list[i]));
+ snprintf((char *)&num_array[i*2], sizeof(num_array) - i*2,
+ "%02X",(uint8_t)(p_ccb->rsp_list[i]));
}
SDP_TRACE_WARNING("result :%s",num_array);
#endif
{
for (int column = 0, x = 0; (ind < len) && (column < col_count); column++, ind++)
{
- x += sprintf((char *)&p_buf[x], "%02x ", p[ind]);
+ x += snprintf((char *)&p_buf[x], sizeof(p_buf) - x, "%02x ", p[ind]);
}
SMP_TRACE_WARNING(" [%03d]: %s", row * col_count, p_buf);
}
{
for (int col = 0, x = 0; (ind < len) && (col < ncols); col++, ind++)
{
- x += sprintf ((char *)&p_buf[len-x-1], "%02x ", p[ind]);
+ x += snprintf ((char *)&p_buf[len-x-1], sizeof(p_buf) - (len-x-1), "%02x ", p[ind]);
}
SMP_TRACE_WARNING("[%03d]: %s", row * ncols, p_buf);
}