From 423cc7443974b3adbb350cf4d943eb9d0b9ed947 Mon Sep 17 00:00:00 2001 From: zhaijunwei Date: Wed, 17 Aug 2022 11:26:11 +0800 Subject: [PATCH] code format-4 Signed-off-by: zhaijunwei --- .../bt_lite/ble/source/ble_util.c | 4 +- hals/communication/bt_lite/ble/source/nble.c | 51 +- .../bt_lite/ble/source/nble_server.c | 37 +- .../wifiservice/source/wifi_hotspot.c | 16 +- hals/utils/file/src/hal_lfs.c | 10 +- tools/wm_tool.c | 450 +++++++++--------- .../include/arch/xt804/csi_core/core_804.h | 6 +- wm800/board/include/wm_wifi_api.h | 5 +- .../platform/arch/xt804/libc/libc_port.c | 316 ++++++------ wm800/board/platform/common/utils/utils.c | 20 +- .../nimble/host/mesh/include/mesh/glue.h | 5 +- .../bt/blehost/nimble/host/mesh/src/crypto.c | 5 +- .../bt/blehost/nimble/host/mesh/src/proxy.c | 8 +- .../bt/blehost/nimble/host/mesh/src/shell.c | 3 +- .../bt/blehost/nimble/host/mesh/src/testing.c | 2 +- .../blehost/nimble/host/mesh/src/transport.c | 26 +- .../bt/blehost/nimble/host/src/ble_att_svr.c | 26 +- 17 files changed, 503 insertions(+), 487 deletions(-) diff --git a/hals/communication/bt_lite/ble/source/ble_util.c b/hals/communication/bt_lite/ble/source/ble_util.c index 95228df..e996edc 100755 --- a/hals/communication/bt_lite/ble/source/ble_util.c +++ b/hals/communication/bt_lite/ble/source/ble_util.c @@ -59,10 +59,10 @@ void tls_bt_dump_hexstring(const char *info, uint8_t *p, int length) { int i = 0, j = 0; printf("%s\r\n", info); - for (i = 0; isvc.svc_def->uuid->type; ble_uuid_flat(ctxt->svc.svc_def->uuid, buf); btuuid.uuid = buf; - if (gatts_struct_func_ptr_cb->serviceAddCb) { - gatts_struct_func_ptr_cb->serviceAddCb(0 /* Always success */, server_if /* */, \ - &btuuid, ctxt->svc.handle); + gatts_struct_func_ptr_cb->serviceAddCb(0, server_if, &btuuid, ctxt->svc.handle); } } break; @@ -141,8 +138,8 @@ static void on_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) ble_uuid_flat(ctxt->chr.chr_def->uuid, buf); btuuid.uuid = buf; if (gatts_struct_func_ptr_cb->characteristicAddCb) { - gatts_struct_func_ptr_cb->characteristicAddCb(0 /* Always success */, server_if /* */, &btuuid , \ - service_handle /* msg->ser_add_char.service_id */, ctxt->chr.val_handle); + gatts_struct_func_ptr_cb->characteristicAddCb(0, server_if, &btuuid , \ + service_handle, ctxt->chr.val_handle); } } @@ -160,8 +157,8 @@ static void on_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) ble_uuid_flat(ctxt->dsc.dsc_def->uuid, buf); btuuid.uuid = buf; if (gatts_struct_func_ptr_cb->descriptorAddCb) { - gatts_struct_func_ptr_cb->descriptorAddCb(0 /* Always success */, server_if /* */, &btuuid , \ - service_handle /* msg->ser_add_char.service_id */, ctxt->dsc.handle); + gatts_struct_func_ptr_cb->descriptorAddCb(0, server_if, &btuuid , \ + service_handle, ctxt->dsc.handle); } } break; @@ -179,10 +176,10 @@ static void ble_server_conn_param_update_slave(void) int rc; struct ble_l2cap_sig_update_params params; - params.itvl_min = 26; - params.itvl_max = 42; + params.itvl_min = 26; // 26:byte alignment + params.itvl_max = 42; // 42:byte alignment params.slave_latency = 0; - params.timeout_multiplier = 500; + params.timeout_multiplier = 500; // 500:byte alignment rc = ble_l2cap_sig_update(g_conn_handle, ¶ms, conn_param_update_cb, NULL); BLE_IF_DEBUG("ble_l2cap_sig_update, rc=%d\n", rc); } @@ -237,7 +234,7 @@ static int ble_server_start_adv(void) } peer_addr.type = g_adv_param.peerAddrType; - memcpy_s(&peer_addr.val[0], sizeof(&peer_addr.val), &g_adv_param.peerAddr.addr[0], 6); + memcpy_s(&peer_addr.val[0], sizeof(&peer_addr.val), &g_adv_param.peerAddr.addr[0], 6); // 6:size BLE_IF_DEBUG("Starting advertising\r\n"); @@ -269,12 +266,11 @@ static int gap_event(struct ble_gap_event *event, void *arg) if (event->connect.status == 0) { rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); - memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), desc.peer_id_addr.val, 6); + memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), desc.peer_id_addr.val, 6); // 6:size g_conn_handle = event->connect.conn_handle; /* see nble_server.c ble_server_gap_event will handle this callback */ if (gatts_struct_func_ptr_cb->connectServerCb) { - gatts_struct_func_ptr_cb->connectServerCb(event->connect.conn_handle, \ - 0 /* Always 0,nimble does not care server if */, &bdaddr); + gatts_struct_func_ptr_cb->connectServerCb(event->connect.conn_handle, 0, &bdaddr); } /* 200 ticks later, perform l2cap level connect param update */ } @@ -286,15 +282,14 @@ static int gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_DISCONNECT: BLE_IF_DEBUG("disconnect reason=%d\r\n", event->disconnect.reason); - memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), event->disconnect.conn.peer_id_addr.val, 6); + memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), event->disconnect.conn.peer_id_addr.val, 6); // 6:size /* see nble_server.c ble_server_gap_event will handle this callback */ if (gatts_struct_func_ptr_cb->disconnectServerCb) { - gatts_struct_func_ptr_cb->disconnectServerCb(event->disconnect.conn.conn_handle, \ - 0 /* Always 0, nimble does not care server if */, &bdaddr); + gatts_struct_func_ptr_cb->disconnectServerCb(event->disconnect.conn.conn_handle, 0, &bdaddr); } - if (event->disconnect.reason == 534) { - // hci error code: 0x16 + 0x200 = 534; // local host terminate the connection; + if (event->disconnect.reason == 534) { // 534:hci error code: 0x16 + 0x200 = 534 + // local host terminate the connection; } else { ble_server_start_adv(); } @@ -303,8 +298,7 @@ static int gap_event(struct ble_gap_event *event, void *arg) if (event->notify_tx.status == BLE_HS_EDONE) { // Note, the first param conn__handle, conn_id??? all servcie share one conn_id, so it is not proper if (gatts_struct_func_ptr_cb->indicationSentCb) { - gatts_struct_func_ptr_cb->indicationSentCb(event->notify_tx.conn_handle, \ - 0 /* event->notify_tx.status */); + gatts_struct_func_ptr_cb->indicationSentCb(event->notify_tx.conn_handle, 0); } } else { /* Application will handle other cases */ @@ -345,7 +339,7 @@ static int gap_event(struct ble_gap_event *event, void *arg) { rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc); assert(rc == 0); - memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), desc.peer_id_addr.val, 6); + memcpy_s(bdaddr.addr, sizeof(bdaddr.addr), desc.peer_id_addr.val, 6); // 6:size if (gap_func_ptr_cb && gap_func_ptr_cb->securityRespondCb)gap_func_ptr_cb->securityRespondCb(&bdaddr); return 0; } @@ -407,7 +401,7 @@ int EnableBtStack(void) tls_nimble_start(); while (bt_adapter_state != WM_BT_STATE_ON) { - tls_os_time_delay(100); + tls_os_time_delay(100); // 100:time unit } bt_system_action = WM_BT_SYSTEM_ACTION_IDLE; @@ -447,7 +441,7 @@ int DisableBtStack(void) /* Application levels resource cleanup */ while (bt_adapter_state == WM_BT_STATE_ON) { - tls_os_time_delay(10); + tls_os_time_delay(10); // 10:time unit } bt_system_action = WM_BT_SYSTEM_ACTION_IDLE; @@ -685,7 +679,7 @@ int BleGattsSendIndication(int serverId, GattsSendIndParam *param) int ReadBtMacAddr(unsigned char *mac, unsigned int len) { - if (len != 6) { + if (len != 6) { // 6:byte alignment return OHOS_BT_STATUS_PARM_INVALID; } @@ -860,5 +854,4 @@ int BleGattsStopServiceEx(int srvcHandle) } } return OHOS_BT_STATUS_SUCCESS; -} - +} \ No newline at end of file diff --git a/hals/communication/bt_lite/ble/source/nble_server.c b/hals/communication/bt_lite/ble/source/nble_server.c index cd5230e..040b7ad 100755 --- a/hals/communication/bt_lite/ble/source/nble_server.c +++ b/hals/communication/bt_lite/ble/source/nble_server.c @@ -83,7 +83,7 @@ void ble_server_gap_event(struct ble_gap_event *event, void *arg) if (event->connect.status == 0) { int rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); - memcpy(bdaddr.addr, desc.peer_id_addr.val, 6); + memcpy(bdaddr.addr, desc.peer_id_addr.val, 6); // 6:size if (gatts_struct_func_ptr_cb && gatts_struct_func_ptr_cb->connectServerCb) { dl_list_for_each(svr_item, &server_list.list, server_elem_t, list) @@ -93,7 +93,7 @@ void ble_server_gap_event(struct ble_gap_event *event, void *arg) } break; case BLE_GAP_EVENT_DISCONNECT: - memcpy(bdaddr.addr, event->disconnect.conn.peer_id_addr.val, 6); + memcpy(bdaddr.addr, event->disconnect.conn.peer_id_addr.val, 6); // 6:size if (gatts_struct_func_ptr_cb && gatts_struct_func_ptr_cb->disconnectServerCb) { dl_list_for_each(svr_item, &server_list.list, server_elem_t, list) gatts_struct_func_ptr_cb->disconnectServerCb(event->disconnect.conn.conn_handle, \ @@ -213,14 +213,14 @@ static int ble_server_gatt_svc_access_func(uint16_t conn_handle, uint16_t attr_h assert(offset <= sizeof(cache_buffer)); om = SLIST_NEXT(om, om_next); } - if (offset>0)ble_server_func_by_attr_handle(attr_handle, ctxt->op, cache_buffer, &offset); - + if (offset > 0) + ble_server_func_by_attr_handle(attr_handle, ctxt->op, cache_buffer, &offset); return 0; } case BLE_GATT_ACCESS_OP_READ_CHR: { ble_server_func_by_attr_handle(attr_handle, ctxt->op, cache_buffer, &length); - if (length>0) { + if (length > 0) { int rc = os_mbuf_append(ctxt->om, &cache_buffer[0], length); return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; } @@ -244,7 +244,7 @@ int ble_server_uuid_init_from_buf(ble_uuid_any_t *uuid, const void *buf, size_t return 0; case OHOS_UUID_TYPE_128_BIT: uuid->u.type = BLE_UUID_TYPE_128; - memcpy_s(uuid->u128.value, sizeof(uuid->u128.value), buf, 16); + memcpy_s(uuid->u128.value, sizeof(uuid->u128.value), buf, 16); // 16:size return 0; default: return 0; @@ -285,7 +285,7 @@ int ble_server_alloc(BleGattService *srvcinfo) serv_elem->srvc_count = 0; // presearch to get the counter of character and descriptor; - for (i = 0; iattrNum; i++) { + for (i = 0; i < srvcinfo->attrNum; i++) { if (srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_SERVICE) { srvc_counter++; } else if (srvcinfo->attrList[i].attrType == OHOS_BLE_ATTRIB_TYPE_CHAR) { @@ -304,14 +304,14 @@ int ble_server_alloc(BleGattService *srvcinfo) BLE_IF_DEBUG("Adding service srvc=%d, char=%d, dsc=%d\r\n", srvc_counter, char_counter, desc_counter); /* alloc service array */ - gatt_svc_array = (struct ble_gatt_svc_def *)tls_mem_alloc(2*sizeof(struct ble_gatt_svc_def)); + gatt_svc_array = (struct ble_gatt_svc_def *)tls_mem_alloc(2 * sizeof(struct ble_gatt_svc_def)); // 2:byte alignment assert(gatt_svc_array != NULL); - memset_s(gatt_svc_array, sizeof(gatt_svc_array), 0, 2*sizeof(struct ble_gatt_svc_def)); + memset_s(gatt_svc_array, sizeof(gatt_svc_array), 0, 2 * sizeof(struct ble_gatt_svc_def)); // 2:byte alignment /* prealloc charactertistic array */ - gatt_chr_array = (struct ble_gatt_chr_def *)tls_mem_alloc((1+char_counter) * sizeof(struct ble_gatt_chr_def)); + gatt_chr_array = (struct ble_gatt_chr_def *)tls_mem_alloc((1 + char_counter) * sizeof(struct ble_gatt_chr_def)); assert(gatt_chr_array != NULL); - memset_s(gatt_chr_array, sizeof(gatt_chr_array), 0, (1+char_counter) * sizeof(struct ble_gatt_chr_def)); + memset_s(gatt_chr_array, sizeof(gatt_chr_array), 0, (1 + char_counter) * sizeof(struct ble_gatt_chr_def)); /* preappending to character array */ gatt_svc_array[0].characteristics = gatt_chr_array; @@ -346,10 +346,8 @@ int ble_server_alloc(BleGattService *srvcinfo) /* process stack env */ gatt_chr_array[serv_elem->srvc_count].uuid = &srvc_sub_elem->uuid; gatt_chr_array[serv_elem->srvc_count].access_cb = ble_server_gatt_svc_access_func; - // gatt_chr_array[serv_elem->srvc_count].flags = srvcinfo->attrList[i].properties \ - |srvcinfo->attrList[i].permission<<8; gatt_chr_array[serv_elem->srvc_count].flags = srvcinfo->attrList[i].properties; - gatt_chr_array[serv_elem->srvc_count].min_key_size = 16; + gatt_chr_array[serv_elem->srvc_count].min_key_size = 16; // 16:byte alignment gatt_chr_array[serv_elem->srvc_count].val_handle = &srvc_sub_elem->attr_handle; gatt_chr_array[serv_elem->srvc_count].arg = (void*)&srvc_elem->attr_handle; \ // give the service handle as arg, char added callback will handle it; @@ -370,12 +368,15 @@ int ble_server_alloc(BleGattService *srvcinfo) (gatt_chr_array[serv_elem->srvc_count].flags & BLE_GATT_CHR_F_INDICATE)) { // NimBLE stack will auto add the cccd. } else { - gatt_dsc_array = (struct ble_gatt_dsc_def *)tls_mem_alloc(2*sizeof(struct ble_gatt_dsc_def)); - memset_s(gatt_dsc_array, sizeof(gatt_dsc_array), 0, 2*sizeof(struct ble_gatt_dsc_def)); + gatt_dsc_array = + (struct ble_gatt_dsc_def *)tls_mem_alloc(2 * sizeof(struct ble_gatt_dsc_def)); // 2:byte alignment + memset_s(gatt_dsc_array, sizeof(gatt_dsc_array), 0, + 2 * sizeof(struct ble_gatt_dsc_def)); // 2:byte alignment gatt_dsc_array[0].uuid = &srvc_sub_elem->uuid; gatt_dsc_array[0].access_cb = ble_server_gatt_svc_access_func; - gatt_dsc_array[0].att_flags = srvcinfo->attrList[i].properties |srvcinfo->attrList[i].permission<<8; - gatt_dsc_array[0].min_key_size = 16; + gatt_dsc_array[0].att_flags = + srvcinfo->attrList[i].properties |srvcinfo->attrList[i].permission << 8; // 8:byte alignment + gatt_dsc_array[0].min_key_size = 16; // 16:byte alignment gatt_dsc_array[0].arg = (void*)&srvc_elem->attr_handle; // give the service handle as arg, char added callback will handle it; gatt_chr_array[serv_elem->srvc_count].descriptors = gatt_dsc_array; diff --git a/hals/communication/wifi_lite/wifiservice/source/wifi_hotspot.c b/hals/communication/wifi_lite/wifiservice/source/wifi_hotspot.c index 8fc8d5a..f69605b 100755 --- a/hals/communication/wifi_lite/wifiservice/source/wifi_hotspot.c +++ b/hals/communication/wifi_lite/wifiservice/source/wifi_hotspot.c @@ -113,14 +113,14 @@ WifiErrorCode EnableHotspot() apinfo.keyinfo.index = 1; // 1-4 (only wep) } struct tls_ip_info_t ipinfo = {0}; - ipinfo.ip_addr[0] = 192; - ipinfo.ip_addr[1] = 168; - ipinfo.ip_addr[2] = 1; - ipinfo.ip_addr[3] = 1; - ipinfo.netmask[0] = 255; - ipinfo.netmask[1] = 255; - ipinfo.netmask[2] = 255; - ipinfo.netmask[3] = 0; + ipinfo.ip_addr[0] = 192; // 192:byte alignment + ipinfo.ip_addr[1] = 168; // 168:byte alignment + ipinfo.ip_addr[2] = 1; // 2:array element + ipinfo.ip_addr[3] = 1; // 3:array element + ipinfo.netmask[0] = 255; // 255:byte alignment + ipinfo.netmask[1] = 255; // 255:byte alignment + ipinfo.netmask[2] = 255; // 255:byte alignment, 2:array element + ipinfo.netmask[3] = 0; // 3:array element int retval = tls_wifi_softap_create(&apinfo, &ipinfo); if (retval != WM_SUCCESS) { printf("[wifi_service]:EnableHotspot tls_wifi_softap_create fail, err = %d\n", retval); diff --git a/hals/utils/file/src/hal_lfs.c b/hals/utils/file/src/hal_lfs.c index bd7d02c..1490a74 100755 --- a/hals/utils/file/src/hal_lfs.c +++ b/hals/utils/file/src/hal_lfs.c @@ -62,15 +62,15 @@ static char *_path_convert(const char *path) int len; char *target_path; - len = strlen(path) + 8; + len = strlen(path) + 8; // 8:byte alignment target_path = (char *)malloc(len); if (target_path == NULL) { return NULL; } memset_s(target_path, len, 0, len); int i, j = 0; - memcpy_s(target_path, sizeof(target_path), "/data/", 6); - j += 6; + memcpy_s(target_path, sizeof(target_path), "/data/", 6); // 6:size + j += 6; // 6:byte alignment for (i = 0; i < strlen(path); i++) { if (path[i] != '/') { target_path[j++] = path[i]; @@ -113,7 +113,7 @@ int HalFileClose(int fd) if (fd < 0) { return -1; } - ret = close(fd-1); + ret = close(fd - 1); if (ret) { return -1; } @@ -127,7 +127,7 @@ int HalFileRead(int fd, char* buf, unsigned int len) if (fd < 0 || (buf == NULL) || (len == 0)) { return -1; } - ret = read(fd-1, buf, len); + ret = read(fd - 1, buf, len); return ret; } diff --git a/tools/wm_tool.c b/tools/wm_tool.c index dce572d..a1b4052 100755 --- a/tools/wm_tool.c +++ b/tools/wm_tool.c @@ -316,23 +316,23 @@ static void wm_tool_stdin_to_uart(void); #define DO1(buf) do { s1 += *buf++; \ s2 += s1; \ -}while (0) +} while (0) #define DO2(buf) do { DO1(buf); \ DO1(buf); \ -}while (0) +} while (0) #define DO4(buf) do { DO2(buf); \ DO2(buf); \ -}while (0) +} while (0) #define DO8(buf) do { DO4(buf); \ DO4(buf); \ -}while (0) +} while (0) #define DO16(buf) do { DO8(buf); \ DO8(buf); \ -}while (0) +} while (0) #define Z_OK 0 #define Z_STREAM_END 1 @@ -421,10 +421,10 @@ static void wm_tool_stdin_to_uart(void); #define put_short(s, w) do { \ put_byte((s), (uch)((w) & 0xff)); \ put_byte((s), (uch)((ush)(w) >> 8)); \ -}while (0) +} while (0) #define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH((s), (s)->ins_h, (s)->window[(str) + MIN_MATCH-1]), \ + (UPDATE_HASH((s), (s)->ins_h, (s)->window[(str) + MIN_MATCH - 1]), \ (s)->prev[(str) & (s)->w_mask] = (match_head) = (s)->head[(s)->ins_h], \ (s)->head[(s)->ins_h] = (str)) @@ -433,7 +433,7 @@ static void wm_tool_stdin_to_uart(void); #define check_match(s, start, match, length) #define d_code(dist) \ - ((dist) < 256 ? dist_code[dist] : dist_code[256+((dist)>>7)]) + ((dist) < 256 ? dist_code[dist] : dist_code[256 + ((dist) >> 7)]) #define FLUSH_BLOCK_ONLY(s, eof) do { \ ct_flush_block((s), ((s)->block_start >= 0L ? \ @@ -940,7 +940,7 @@ local uLong crc32(crc, buf, len) crc = crc ^ 0xffffffffL; if (len) { do { - crc = wm_tool_crc32_tab[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); + crc = wm_tool_crc32_tab[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); // 8:byte alignment } while (--len); } return crc ^ 0xffffffffL; @@ -977,7 +977,7 @@ local uLong adler32(adler, buf, len) uInt len; { unsigned long s1 = adler & 0xffff; - unsigned long s2 = (adler >> 16) & 0xffff; + unsigned long s2 = (adler >> 16) & 0xffff; // 16:byte alignment int k; if (buf == Z_NULL) { @@ -987,9 +987,9 @@ local uLong adler32(adler, buf, len) while (len > 0) { k = len < NMAX ? len : NMAX; len -= k; - while (k >= 16) { + while (k >= 16) { // 16:byte alignment DO16(buf); - k -= 16; + k -= 16; // 16:byte alignment } if (k != 0) { do { @@ -999,7 +999,7 @@ local uLong adler32(adler, buf, len) s1 %= BASE; s2 %= BASE; } - return (s2 << 16) | s1; + return (s2 << 16) | s1; // 16:byte alignment } local int read_buf(strm, buf, size) @@ -1150,9 +1150,9 @@ local void putLong (file, x) uLong x; { int n; - for (n = 0; n < 4; n++) { + for (n = 0; n < 4; n++) { // 4:byte alignment fputc((int)(x & 0xff), file); - x >>= 8; + x >>= 8; // 8:byte alignment } } @@ -1160,10 +1160,10 @@ local uLong getLong (buf) Byte *buf; { uLong x = 0; - Byte *p = buf+4; + Byte *p = buf + 4; // 4:byte alignment do { - x <<= 8; + x <<= 8; // 8:byte alignment x |= *--p; } while (p != buf); return x; @@ -1195,12 +1195,12 @@ local void gen_codes (tree, max_code, bl_count) * without bit reversal. */ for (bits = 1; bits <= MAX_BITS; bits++) { - next_code[bits] = code = (code + bl_count[bits-1]) << 1; + next_code[bits] = code = (code + bl_count[bits - 1]) << 1; } /* Check that the bit counts in bl_count are consistent. The last code * must be all ones. */ - Assert (code + bl_count[MAX_BITS]-1 == (1< dist code (0..29) */ dist = 0; - for (code = 0 ; code < 16; code++) { + for (code = 0 ; code < 16; code++) { // 16:byte alignment base_dist[code] = dist; - for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ + dist >>= 7; /* from now on, all distances are divided by 128 */ // 7:byte alignment for (; code < D_CODES; code++) { - base_dist[code] = dist << 7; - for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { - dist_code[256 + dist++] = (uch)code; + base_dist[code] = dist << 7; // 7:byte alignment + for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) { // 7:byte alignment + dist_code[256 + dist++] = (uch)code; // 256:byte alignment } } - Assert (dist == 256, "ct_static_init: 256+dist != 512"); + Assert (dist == 256, "ct_static_init: 256+dist != 512"); // 256:byte alignment /* Construct the codes of the static literal tree */ for (bits = 0; bits <= MAX_BITS; bits++) { bl_count[bits] = 0; } n = 0; - while (n <= 143) { - static_ltree[n++].Len = 8, bl_count[8]++; + while (n <= 143) { // 143:byte alignment + static_ltree[n++].Len = 8, bl_count[8]++; // 8:byte alignment } - while (n <= 255) { - static_ltree[n++].Len = 9, bl_count[9]++; + while (n <= 255) { // 255:byte alignment + static_ltree[n++].Len = 9, bl_count[9]++; // 9:byte alignment } - while (n <= 279) { - static_ltree[n++].Len = 7, bl_count[7]++; + while (n <= 279) { // 279:byte alignment + static_ltree[n++].Len = 7, bl_count[7]++; // 7:byte alignment } - while (n <= 287) { - static_ltree[n++].Len = 8, bl_count[8]++; + while (n <= 287) { // 287:byte alignment + static_ltree[n++].Len = 8, bl_count[8]++; // 8:byte alignment } /* Codes 286 and 287 do not exist, but we must include them in the * tree construction to get a canonical Huffman tree (longest code * all ones) */ - gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); + gen_codes((ct_data *)static_ltree, L_CODES + 1, bl_count); /* The static distance tree is trivial: */ for (n = 0; n < D_CODES; n++) { - static_dtree[n].Len = 5; - static_dtree[n].Code = bi_reverse(n, 5); + static_dtree[n].Len = 5; // 5:byte alignment + static_dtree[n].Code = bi_reverse(n, 5); // 5:byte alignment } } @@ -1292,13 +1292,13 @@ local void init_block(s) int n; /* iterates over tree elements */ /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) { + for (n = 0; n < L_CODES; n++) { s->dyn_ltree[n].Freq = 0; } - for (n = 0; n < D_CODES; n++) { + for (n = 0; n < D_CODES; n++) { s->dyn_dtree[n].Freq = 0; } - for (n = 0; n < BL_CODES; n++) { + for (n = 0; n < BL_CODES;n++) { s->bl_tree[n].Freq = 0; } @@ -1432,7 +1432,8 @@ local int deflateInit2 (strm, level, method, windowBits, memLevel, strategy) windowBits = -windowBits; } if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != DEFLATED || - windowBits < 8 || windowBits > 15 || level < 1 || level > 9) { + windowBits < 8 || windowBits > 15 || // 8:byte alignment, 15:byte alignment + level < 1 || level > 9) { // 9:byte alignment return Z_STREAM_ERROR; } s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); @@ -1447,27 +1448,26 @@ local int deflateInit2 (strm, level, method, windowBits, memLevel, strategy) s->w_size = 1 << s->w_bits; s->w_mask = s->w_size - 1; - s->hash_bits = memLevel + 7; + s->hash_bits = memLevel + 7; // 7:byte alignment s->hash_size = 1 << s->hash_bits; s->hash_mask = s->hash_size - 1; s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); - s->window = (Byte*) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); + s->window = (Byte*) ZALLOC(strm, s->w_size, 2 * sizeof(Byte)); // 2:byte alignment s->prev = (Pos*) ZALLOC(strm, s->w_size, sizeof(Pos)); s->head = (Pos*) ZALLOC(strm, s->hash_size, sizeof(Pos)); - s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ + s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ // 6:byte alignment - s->pending_buf = (uch*) ZALLOC(strm, s->lit_bufsize, 2*sizeof(ush)); + s->pending_buf = (uch*) ZALLOC(strm, s->lit_bufsize, 2 * sizeof(ush)); // 2:byte alignment - if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || - s->pending_buf == Z_NULL) { - strm->msg = z_errmsg[1-Z_MEM_ERROR]; + if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { + strm->msg = z_errmsg[1 - Z_MEM_ERROR]; deflateEnd (strm); return Z_MEM_ERROR; } s->d_buf = (ush*) &(s->pending_buf[s->lit_bufsize]); - s->l_buf = (uch*) &(s->pending_buf[3*s->lit_bufsize]); + s->l_buf = (uch*) &(s->pending_buf[3 * s->lit_bufsize]); // 3:byte alignment /* We overlay pending_buf and d_buf+l_buf. This works since the average * output size for (length,distance) codes is <= 32 bits (worst case * is 15+15+13=33). @@ -1511,7 +1511,7 @@ int w; } /* set window size */ - if (w < 8 || w > 15) { + if (w < 8 || w > 15) { // 8:window size, 15:window size inflateEnd(z); return Z_STREAM_ERROR; } @@ -1523,7 +1523,7 @@ local void putShortMSB (s, b) deflate_state *s; uInt b; { - put_byte(s, (Byte)(b >> 8)); + put_byte(s, (Byte)(b >> 8)); // 8:byte alignment put_byte(s, (Byte)(b & 0xff)); } @@ -1610,7 +1610,7 @@ local void fill_window(s) * Otherwise, window_size == 2*WSIZE so more >= 2. * If there was sliding, more >= WSIZE. So in all cases, more >= 2. */ - Assert(more >= 2, "more < 2"); + Assert(more >= 2, "more < 2"); // 2:byte alignment n = read_buf(s->strm, (char*)s->window + s->strstart + s->lookahead, more); @@ -1642,10 +1642,10 @@ local int longest_match(s, cur_match) */ register Byte *strend = s->window + s->strstart + MAX_MATCH - 1; register ush scan_start = *(ush*)scan; - register ush scan_end = *(ush*)(scan+best_len-1); + register ush scan_end = *(ush*)(scan + best_len-1); #else register Byte *strend = s->window + s->strstart + MAX_MATCH; - register Byte scan_end1 = scan[best_len-1]; + register Byte scan_end1 = scan[best_len - 1]; register Byte scan_end = scan[best_len]; #endif @@ -1656,7 +1656,7 @@ local int longest_match(s, cur_match) /* Do not waste too much time if we already have a good match: */ if (s->prev_length >= s->good_match) { - chain_length >>= 2; + chain_length >>= 2; // 2:byte alignment } Assert(s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); @@ -1667,11 +1667,11 @@ local int longest_match(s, cur_match) /* Skip to next match if the match length cannot increase * or if the match length is less than 2: */ -#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) +#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) // 258:byte alignment /* This code assumes sizeof(unsigned short) == 2. Do not use * UNALIGNED_OK if your compiler uses a different size. */ - if (*(ush*)(match+best_len-1) != scan_end || + if (*(ush*)(match+best_len - 1) != scan_end || *(ush*)match != scan_start) continue; /* It is not necessary to compare scan[2] and match[2] since they are @@ -1685,15 +1685,15 @@ local int longest_match(s, cur_match) */ scan++, match++; do { - } while (*(ush*)(scan+=2) == *(ush*)(match+=2) && - *(ush*)(scan+=2) == *(ush*)(match+=2) && - *(ush*)(scan+=2) == *(ush*)(match+=2) && - *(ush*)(scan+=2) == *(ush*)(match+=2) && + } while (*(ush*)(scan+=2) == *(ush*)(match+=2) && // 2:byte alignment + *(ush*)(scan+=2) == *(ush*)(match+=2) && // 2:byte alignment + *(ush*)(scan+=2) == *(ush*)(match+=2) && // 2:byte alignment + *(ush*)(scan+=2) == *(ush*)(match+=2) && // 2:byte alignment scan < strend); /* The funny "do {}" generates better code on most compilers */ /* Here, scan <= window+strstart+257 */ - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + Assert(scan <= s->window + (unsigned)(s->window_size - 1), "wild scan"); if (*scan == *match) scan++; len = (MAX_MATCH - 1) - (int)(strend-scan); @@ -1714,7 +1714,7 @@ local int longest_match(s, cur_match) * are always equal when the other bytes match, given that * the hash keys are equal and that HASH_BITS >= 8. */ - scan += 2, match++; + scan += 2, match++; // 2:byte alignment /* We check for insufficient lookahead only every 8th comparison; * the 256th check will be made at strstart+258. @@ -1726,7 +1726,7 @@ local int longest_match(s, cur_match) *++scan == *++match && *++scan == *++match && scan < strend); - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + Assert(scan <= s->window + (unsigned)(s->window_size - 1), "wild scan"); len = MAX_MATCH - (int)(strend - scan); scan = strend - MAX_MATCH; @@ -1770,29 +1770,28 @@ local int ct_tally (s, dist, lc) (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && (ush)d_code(dist) < (ush)D_CODES, "ct_tally: bad match"); - s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++; + s->dyn_ltree[length_code[lc] + LITERALS + 1].Freq++; s->dyn_dtree[d_code(dist)].Freq++; } /* Try to guess if it is profitable to stop the current block here */ - if (s->level > 2 && (s->last_lit & 0xfff) == 0) { + if (s->level > 2 && (s->last_lit & 0xfff) == 0) { // 2:byte alignment /* Compute an upper bound for the compressed length */ - ulg out_length = (ulg)s->last_lit*8L; + ulg out_length = (ulg)s->last_lit * 8L; ulg in_length = (ulg)s->strstart - s->block_start; int dcode; for (dcode = 0; dcode < D_CODES; dcode++) { - out_length += (ulg)s->dyn_dtree[dcode].Freq * - (5L+extra_dbits[dcode]); + out_length += (ulg)s->dyn_dtree[dcode].Freq * (5L + extra_dbits[dcode]); } - out_length >>= 3; + out_length >>= 3; // 3:byte alignment - if (s->matches < s->last_lit/2 && out_length < in_length/2) { + if (s->matches < s->last_lit / 2 && out_length < in_length / 2) { // 2:byte alignment return 1; } } - return (s->last_lit == s->lit_bufsize-1); + return (s->last_lit == s->lit_bufsize - 1); /* We avoid equality with lit_bufsize because of wraparound at 64K - * on 16 bit machines and because stored blocks are restricted to + * on 16 bit machines and because stored fblocks are restricted to * 64K-1 bytes. */ } @@ -1803,16 +1802,16 @@ local void set_data_type(s) int n = 0; unsigned ascii_freq = 0; unsigned bin_freq = 0; - while (n < 7) { + while (n < 7) { // 7:byte alignment bin_freq += s->dyn_ltree[n++].Freq; } - while (n < 128) { + while (n < 128) { // 128:byte alignment ascii_freq += s->dyn_ltree[n++].Freq; } while (n < LITERALS) { bin_freq += s->dyn_ltree[n++].Freq; } - s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII); + s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII); // 2:byte alignment } local void pqdownheap(s, tree, k) @@ -1825,7 +1824,7 @@ local void pqdownheap(s, tree, k) while (j <= s->heap_len) { /* Set j to the smallest of the two sons: */ if (j < s->heap_len && - smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { + smaller(tree, s->heap[j + 1], s->heap[j], s->depth)) { j++; } /* Exit if v is smaller than both sons */ @@ -1869,7 +1868,7 @@ local void gen_bitlen(s, desc) */ tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ - for (h = s->heap_max+1; h < HEAP_SIZE; h++) { + for (h = s->heap_max + 1; h < HEAP_SIZE; h++) { n = s->heap[h]; bits = tree[tree[n].Dad].Len + 1; if (bits > max_length) { @@ -1885,7 +1884,7 @@ local void gen_bitlen(s, desc) s->bl_count[bits]++; xbits = 0; if (n >= base) { - xbits = extra[n-base]; + xbits = extra[n - base]; } f = tree[n].Freq; s->opt_len += (ulg)f * (bits + xbits); @@ -1906,12 +1905,12 @@ local void gen_bitlen(s, desc) bits--; } s->bl_count[bits]--; /* move one leaf down the tree */ - s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ + s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ // 2:byte alignment s->bl_count[max_length]--; /* The brother of the overflow item also moves one step up, * but this does not affect bl_count[max_length] */ - overflow -= 2; + overflow -= 2; // 2:byte alignment } while (overflow > 0); /* Now recompute all bit lengths, scanning in increasing frequency. @@ -1968,8 +1967,8 @@ local void build_tree(s, desc) * possible code. So to avoid special checks later on we force at least * two codes of non zero frequency. */ - while (s->heap_len < 2) { - new = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); + while (s->heap_len < 2) { // 2:byte alignment + new = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); // 2:byte alignment tree[new].Freq = 1; s->depth[new] = 0; s->opt_len--; @@ -1983,7 +1982,7 @@ local void build_tree(s, desc) /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, * establish sub-heaps of increasing lengths: */ - for (n = s->heap_len/2; n >= 1; n--) { + for (n = s->heap_len / 2; n >= 1; n--) { // 2:byte alignment pqdownheap(s, tree, n); } @@ -2010,7 +2009,7 @@ local void build_tree(s, desc) /* and insert the new node in the heap */ s->heap[SMALLEST] = node++; pqdownheap(s, tree, SMALLEST); - } while (s->heap_len >= 2); + } while (s->heap_len >= 2); // 2:byte alignment s->heap[--(s->heap_max)] = s->heap[SMALLEST]; @@ -2037,9 +2036,9 @@ local void scan_tree (s, tree, max_code) int min_count = 4; /* min repeat count */ if (nextlen == 0) { - max_count = 138, min_count = 3; + max_count = 138, min_count = 3; // 3:byte alignment, 138:byte alignment } - tree[max_code+1].Len = (ush)0xffff; /* guard */ + tree[max_code + 1].Len = (ush)0xffff; /* guard */ for (n = 0; n <= max_code; n++) { curlen = nextlen; @@ -2053,7 +2052,7 @@ local void scan_tree (s, tree, max_code) s->bl_tree[curlen].Freq++; } s->bl_tree[REP_3_6].Freq++; - } else if (count <= 10) { + } else if (count <= 10) { // 10:byte alignment s->bl_tree[REPZ_3_10].Freq++; } else { s->bl_tree[REPZ_11_138].Freq++; @@ -2061,11 +2060,11 @@ local void scan_tree (s, tree, max_code) count = 0; prevlen = curlen; if (nextlen == 0) { - max_count = 138, min_count = 3; + max_count = 138, min_count = 3; // 3:byte alignment, 138:byte alignment } else if (curlen == nextlen) { - max_count = 6, min_count = 3; + max_count = 6, min_count = 3; // 3:byte alignment, 6:byte alignment } else { - max_count = 7, min_count = 4; + max_count = 7, min_count = 4; // 7:byte alignment, 4:byte alignment } } } @@ -2089,13 +2088,13 @@ local int build_bl_tree(s) * requires that at least 4 bit length codes be sent. (appnote.txt says * 3 but the actual value used is 4.) */ - for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { + for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { // 3:byte alignment if (s->bl_tree[bl_order[max_blindex]].Len != 0) { break; } } /* Update opt_len to include the bit length tree and counts */ - s->opt_len += 3*(max_blindex+1) + 5+5+4; + s->opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; // 3:byte alignment, 4:byte alignment, 5:byte alignment return max_blindex; } @@ -2106,7 +2105,7 @@ local void send_bits(s, value, length) int length; /* number of bits */ { #ifdef DEBUG - Assert(length > 0 && length <= 15, "invalid length"); + Assert(length > 0 && length <= 15, "invalid length"); // 15:byte alignment s->bits_sent += (ulg)length; #endif /* If not enough room in bi_buf, use (valid) bits from bi_buf and @@ -2127,7 +2126,7 @@ local void send_bits(s, value, length) local void bi_windup(s) deflate_state *s; { - if (s->bi_valid > 8) { + if (s->bi_valid > 8) { // 8:byte alignment put_short(s, s->bi_buf); } else if (s->bi_valid > 0) { put_byte(s, (Byte)s->bi_buf); @@ -2135,7 +2134,7 @@ local void bi_windup(s) s->bi_buf = 0; s->bi_valid = 0; #ifdef DEBUG - s->bits_sent = (s->bits_sent+7) & ~7; + s->bits_sent = (s->bits_sent + 7) & ~7; // 7:byte alignment #endif } @@ -2151,11 +2150,11 @@ local void copy_block(s, buf, len, header) put_short(s, (ush)len); put_short(s, (ush)~len); #ifdef DEBUG - s->bits_sent += 2*16; + s->bits_sent += 2 * 16; // 2:byte alignment, 16:byte alignment #endif } #ifdef DEBUG - s->bits_sent += (ulg)len<<3; + s->bits_sent += (ulg)len << 3; // 3:byte alignment #endif while (len--) { put_byte(s, *buf++); @@ -2182,7 +2181,7 @@ local void compress_block(s, ltree, dtree) } else { /* Here, lc is the match length - MIN_MATCH */ code = length_code[lc]; - send_code(s, code+LITERALS+1, ltree); /* send the length code */ + send_code(s, code+LITERALS + 1, ltree); /* send the length code */ extra = extra_lbits[code]; if (extra != 0) { lc -= base_length[code]; @@ -2201,7 +2200,7 @@ local void compress_block(s, ltree, dtree) } /* literal or match pair ? */ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow"); + Assert(s->pending < s->lit_bufsize + 2 * lx, "pendingBuf overflow"); } while (lx < s->last_lit); } send_code(s, END_BLOCK, ltree); @@ -2221,12 +2220,12 @@ local void send_tree (s, tree, max_code) int min_count = 4; /* min repeat count */ if (nextlen == 0) { - max_count = 138, min_count = 3; + max_count = 138, min_count = 3; // 138:byte alignment, 3:byte alignment } for (n = 0; n <= max_code; n++) { curlen = nextlen; - nextlen = tree[n+1].Len; + nextlen = tree[n + 1].Len; if (++count < max_count && curlen == nextlen) { continue; } else if (count < min_count) { @@ -2238,24 +2237,24 @@ local void send_tree (s, tree, max_code) send_code(s, curlen, s->bl_tree); count--; } - Assert(count >= 3 && count <= 6, " 3_6?"); + Assert(count >= 3 && count <= 6, " 3_6?"); // 3:byte alignment, 6:byte alignment send_code(s, REP_3_6, s->bl_tree); - send_bits(s, count-3, 2); - } else if (count <= 10) { + send_bits(s, count - 3, 2); // 3:byte alignment, 2:byte alignment + } else if (count <= 10) { // 10:byte alignment send_code(s, REPZ_3_10, s->bl_tree); - send_bits(s, count-3, 3); + send_bits(s, count - 3, 3); // 3:byte alignment } else { send_code(s, REPZ_11_138, s->bl_tree); - send_bits(s, count-11, 7); + send_bits(s, count - 11, 7); // 11:byte alignment, 7:byte alignment } count = 0; prevlen = curlen; if (nextlen == 0) { - max_count = 138, min_count = 3; + max_count = 138, min_count = 3; // 138:byte alignment, 3:byte alignment } else if (curlen == nextlen) { - max_count = 6, min_count = 3; + max_count = 6, min_count = 3; // 6:byte alignment, 3:byte alignment } else { - max_count = 7, min_count = 4; + max_count = 7, min_count = 4; // 7:byte alignment, 4:byte alignment } } } @@ -2266,19 +2265,19 @@ local void send_all_trees(s, lcodes, dcodes, blcodes) { int rank; /* index in bl_order */ - Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); // 257:byte alignment, 4:byte alignment Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, "too many codes"); - send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ - send_bits(s, dcodes-1, 5); - send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ + send_bits(s, lcodes - 257, 5); // 257:byte alignment, 5:byte alignment + send_bits(s, dcodes-1, 5); // 5:byte alignment + send_bits(s, blcodes - 4, 4); // 4:byte alignment for (rank = 0; rank < blcodes; rank++) { - send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); + send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); // 3:byte alignment } - send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ + send_tree(s, (ct_data *)s->dyn_ltree, lcodes - 1); /* literal tree */ - send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ + send_tree(s, (ct_data *)s->dyn_dtree, dcodes - 1); /* distance tree */ } ulg ct_flush_block(s, buf, stored_len, eof) @@ -2310,8 +2309,8 @@ ulg ct_flush_block(s, buf, stored_len, eof) max_blindex = build_bl_tree(s); /* Determine the best encoding. Compute first the block length in bytes */ - opt_lenb = (s->opt_len+3+7)>>3; - static_lenb = (s->static_len+3+7)>>3; + opt_lenb = (s->opt_len + 3 + 7) >> 3; // 7:byte alignment, 3:byte alignment + static_lenb = (s->static_len + 3 + 7) >> 3; // 3:byte alignment, 7:byte alignment if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; @@ -2329,21 +2328,21 @@ ulg ct_flush_block(s, buf, stored_len, eof) * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to * transform a block into a stored block. */ - send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ - s->compressed_len = (s->compressed_len + 3 + 7) & ~7L; - s->compressed_len += (stored_len + 4) << 3; + send_bits(s, (STORED_BLOCK << 1) + eof, 3); // 3:byte alignment /* send block type */ + s->compressed_len = (s->compressed_len + 3 + 7) & ~7L; // 7:byte alignment, 3:byte alignment + s->compressed_len += (stored_len + 4) << 3; // 3:byte alignment, 4:byte alignment copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ } else if (static_lenb == opt_lenb) { - send_bits(s, (STATIC_TREES<<1)+eof, 3); + send_bits(s, (STATIC_TREES << 1) + eof, 3); // 3:byte alignment compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); - s->compressed_len += 3 + s->static_len; + s->compressed_len += 3 + s->static_len; // 3:byte alignment } else { - send_bits(s, (DYN_TREES<<1)+eof, 3); - send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, + send_bits(s, (DYN_TREES << 1) + eof, 3); // 3:byte alignment + send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code + 1, max_blindex+1); compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); - s->compressed_len += 3 + s->opt_len; + s->compressed_len += 3 + s->opt_len; // 3:byte alignment } Assert (s->compressed_len == s->bits_sent, "bad compressed size"); init_block(s); @@ -2353,7 +2352,7 @@ ulg ct_flush_block(s, buf, stored_len, eof) s->compressed_len += 7; /* align on byte boundary */ } - return s->compressed_len >> 3; + return s->compressed_len >> 3; // 3:byte alignment } local int deflate_fast(s, flush) @@ -2363,7 +2362,7 @@ local int deflate_fast(s, flush) IPos hash_head; /* head of the hash chain */ int bflush; /* set if current block must be flushed */ - s->prev_length = MIN_MATCH-1; + s->prev_length = MIN_MATCH - 1; for (;;) { /* Make sure that we always have enough lookahead, except @@ -2396,7 +2395,7 @@ local int deflate_fast(s, flush) * of the string with itself at the start of the input file). */ if (s->strategy != Z_HUFFMAN_ONLY) { - s->match_length = longest_match (s, hash_head); + s->match_length = longest_match(s, hash_head); } /* longest_match() sets match_start */ @@ -2431,7 +2430,7 @@ local int deflate_fast(s, flush) s->strstart += s->match_length; s->match_length = 0; s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); + UPDATE_HASH(s, s->ins_h, s->window[s->strstart + 1]); #if MIN_MATCH != 3 Call UPDATE_HASH() MIN_MATCH-3 more times #endif @@ -2499,20 +2498,20 @@ local int deflate_slow(s, flush) s->match_length = s->lookahead; } - if (s->match_length <= 5 && (s->strategy == Z_FILTERED || + if (s->match_length <= 5 && (s->strategy == Z_FILTERED || // 5:byte alignment (s->match_length == MIN_MATCH && s->strstart - s->match_start > TOO_FAR))) { /* If prev_match is also MIN_MATCH, match_start is garbage * but we will ignore the current match anyway. */ - s->match_length = MIN_MATCH-1; + s->match_length = MIN_MATCH - 1; } } /* If there was a match at the previous step and the current * match is not better, output the previous match: */ if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { - check_match(s, s->strstart-1, s->prev_match, s->prev_length); + check_match(s, s->strstart - 1, s->prev_match, s->prev_length); bflush = ct_tally(s, s->strstart -1 - s->prev_match, s->prev_length - MIN_MATCH); @@ -2520,7 +2519,7 @@ local int deflate_slow(s, flush) /* Insert in hash table all strings up to the end of the match. * strstart-1 and strstart are already inserted. */ - s->lookahead -= s->prev_length-1; + s->lookahead -= s->prev_length - 1; s->prev_length -= 2; do { s->strstart++; @@ -2532,7 +2531,7 @@ local int deflate_slow(s, flush) */ } while (--s->prev_length != 0); s->match_available = 0; - s->match_length = MIN_MATCH-1; + s->match_length = MIN_MATCH - 1; s->strstart++; if (bflush) { @@ -2543,7 +2542,7 @@ local int deflate_slow(s, flush) * single literal. If there was a match but the current match * is longer, truncate the previous match to a single literal. */ - if (ct_tally (s, 0, s->window[s->strstart-1])) { + if (ct_tally (s, 0, s->window[s->strstart - 1])) { FLUSH_BLOCK_ONLY(s, 0); } s->strstart++; @@ -2561,7 +2560,7 @@ local int deflate_slow(s, flush) } } if (s->match_available) { - ct_tally (s, 0, s->window[s->strstart-1]); + ct_tally (s, 0, s->window[s->strstart - 1]); } FLUSH_BLOCK(s, flush == Z_FINISH); @@ -2587,14 +2586,14 @@ local int deflate (strm, flush) /* Write the zlib header */ if (strm->state->status == INIT_STATE) { - uInt header = (DEFLATED + ((strm->state->w_bits-8)<<4)) << 8; - uInt level_flags = (strm->state->level-1) >> 1; + uInt header = (DEFLATED + ((strm->state->w_bits - 8) << 4)) << 8; // 4:byte alignment, 8:byte alignment + uInt level_flags = (strm->state->level - 1) >> 1; - if (level_flags > 3) { - level_flags = 3; + if (level_flags > 3) { // 3:byte alignment + level_flags = 3; // 3:byte alignment } - header |= (level_flags << 6); - header += 31 - (header % 31); + header |= (level_flags << 6); // 3:byte alignment + header += 31 - (header % 31); // 31:byte alignment strm->state->status = BUSY_STATE; putShortMSB(strm->state, header); @@ -2620,7 +2619,7 @@ local int deflate (strm, flush) if (flush == Z_FINISH) { strm->state->status = FINISH_STATE; } - if (strm->state->level <= 3) { + if (strm->state->level <= 3) { // 3:byte alignment if (deflate_fast(strm->state, flush)) { return Z_OK; } @@ -2640,7 +2639,7 @@ local int deflate (strm, flush) } /* Write the zlib trailer (adler32) */ - putShortMSB(strm->state, (uInt)(strm->state->adler >> 16)); + putShortMSB(strm->state, (uInt)(strm->state->adler >> 16)); // 16:byte alignment putShortMSB(strm->state, (uInt)(strm->state->adler & 0xffff)); flush_pending(strm); /* If avail_out is zero, the application will call deflate again @@ -2766,7 +2765,7 @@ local gzFile gz_open (path, mode, fd) /* Write a very simple .gz header: */ fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", GZ_MAGIC_1, GZ_MAGIC_2, - DEFLATED, 0 /* flags */, 0, 0, 0, 0 /* time */, 0 /* xflags */, OS_CODE); + DEFLATED, 0, 0, 0, 0, 0, 0, OS_CODE); } else { /* Check and skip the header: */ @@ -2778,8 +2777,8 @@ local gzFile gz_open (path, mode, fd) Byte osCode; int c; - s->stream.avail_in = fread(s->inbuf, 1, 2, s->file); - if (s->stream.avail_in != 2 || s->inbuf[0] != GZ_MAGIC_1 + s->stream.avail_in = fread(s->inbuf, 1, 2, s->file); // 2:size + if (s->stream.avail_in != 2 || s->inbuf[0] != GZ_MAGIC_1 // 2:byte alignment || s->inbuf[1] != GZ_MAGIC_2) { s->transparent = 1; return (gzFile)s; @@ -2794,7 +2793,7 @@ local gzFile gz_open (path, mode, fd) if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */ long len; err = fscanf(s->file, "%c%c", &c1, &c2); - len = c1 + ((long)c2<<8); + len = c1 + ((long)c2 << 8); // 8:byte alignment fseek(s->file, len, SEEK_CUR); } if ((flags & ORIG_NAME) != 0) { /* skip the original file name */ @@ -2868,7 +2867,7 @@ local int gzclose (file) } if (s->mode == 'w') { - err = gzflush (file, Z_FINISH); + err = gzflush(file, Z_FINISH); if (err != Z_OK) { return destroy((gz_stream *)file); } @@ -2877,7 +2876,7 @@ local int gzclose (file) putLong (s->file, s->stream.total_in); } else if (s->mode == 'r' && s->z_err == Z_STREAM_END) { /* slide CRC and original size if they are at the end of inbuf */ - if ((n = s->stream.avail_in) < 8 && !s->z_eof) { + if ((n = s->stream.avail_in) < 8 && !s->z_eof) { // 8:byte alignment Byte *p = s->inbuf; Byte *q = s->stream.next_in; while (n--) { @@ -2885,13 +2884,13 @@ local int gzclose (file) } n = s->stream.avail_in; - n += fread(p, 1, 8, s->file); + n += fread(p, 1, 8, s->file); // 8:size s->stream.next_in = s->inbuf; } /* check CRC and original size */ if (n < 8 || getLong(s->stream.next_in) != s->crc || - getLong(s->stream.next_in + 4) != s->stream.total_out) { + getLong(s->stream.next_in + 4) != s->stream.total_out) { // 4:byte alignment s->z_err = Z_DATA_ERROR; } } @@ -2936,11 +2935,11 @@ static unsigned int wm_tool_crc32(unsigned int crc, unsigned char *buffer, int s for (i = 0; i < size; i++) { if (mode & WM_TOOL_CRC32_REFLECT_INPUT) { - temp = wm_tool_crc32_reflect(buffer[i], 8); + temp = wm_tool_crc32_reflect(buffer[i], 8); // 8:ch } else { temp = buffer[i]; } - crc = wm_tool_crc32_tab[(crc ^ temp) & 0xff] ^ (crc >> 8); + crc = wm_tool_crc32_tab[(crc ^ temp) & 0xff] ^ (crc >> 8); // 8:byte alignment } return crc ; @@ -2950,7 +2949,7 @@ static unsigned int wm_tool_get_crc32(unsigned char *buffer, int size, wm_tool_c { wm_tool_file_crc = wm_tool_crc32(wm_tool_file_crc, buffer, size, mode); if (mode & WM_TOOL_CRC32_REFLECT_OUTPUT) { - wm_tool_file_crc = wm_tool_crc32_reflect(wm_tool_file_crc, 32); + wm_tool_file_crc = wm_tool_crc32_reflect(wm_tool_file_crc, 32); // 32:size } return wm_tool_file_crc; } @@ -2962,9 +2961,9 @@ static unsigned short wm_tool_get_crc16(unsigned char *ptr, unsigned short count crc = 0; while (count--) { - crc = crc ^ (int) *ptr++ << 8; + crc = crc ^ (int) *ptr++ << 8; // 8:byte alignment - for (i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) { // 8:loop cap if (crc & 0x8000) crc = crc << 1 ^ 0x1021; else @@ -3224,7 +3223,7 @@ static int wm_tool_parse_arv(int argc, char *argv[]) case 'w': { if (optarg[1] == 'M') { - wm_tool_normal_serial_rate = (optarg[0] - 0x30) * 1000000; + wm_tool_normal_serial_rate = (optarg[0] - 0x30) * 1000000; // 1000000:byte alignment } else { wm_tool_normal_serial_rate = strtol(optarg, NULL, 10); } @@ -3233,9 +3232,9 @@ static int wm_tool_parse_arv(int argc, char *argv[]) case 's': { if (optarg[1] == 'M') { - wm_tool_download_serial_rate = (optarg[0] - 0x30) * 1000000; + wm_tool_download_serial_rate = (optarg[0] - 0x30) * 1000000; // 1000000:byte alignment } else { - wm_tool_download_serial_rate = strtol(optarg, NULL, 10); + wm_tool_download_serial_rate = strtol(optarg, NULL, 10); // 10:base } break; } @@ -3312,12 +3311,12 @@ static int wm_tool_parse_arv(int argc, char *argv[]) } case 'u': { - wm_tool_upd_addr = strtol(optarg, NULL, 16); + wm_tool_upd_addr = strtol(optarg, NULL, 16); // 16:value of base break; } case 'r': { - wm_tool_run_addr = strtol(optarg, NULL, 16); + wm_tool_run_addr = strtol(optarg, NULL, 16); // 16:value of base break; } case 'D': @@ -3348,17 +3347,17 @@ static int wm_tool_parse_arv(int argc, char *argv[]) } case 'H': { - wm_tool_image_header = strtol(optarg, NULL, 16); + wm_tool_image_header = strtol(optarg, NULL, 16); // 16:value of base break; } case 'n': { - wm_tool_next_image_header = strtol(optarg, NULL, 16); + wm_tool_next_image_header = strtol(optarg, NULL, 16); // 16:value of base break; } case 'U': { - wm_tool_image_upd_no = strtol(optarg, NULL, 16); + wm_tool_image_upd_no = strtol(optarg, NULL, 16); // 16:value of base break; } default: @@ -3430,7 +3429,7 @@ static int wm_tool_pack_image(const char *outfile) /* calculate image's header's CRC */ wm_tool_file_crc = 0xFFFFFFFF; - wm_tool_get_crc32((unsigned char *)&fbooter, sizeof(wm_tool_firmware_booter_t) - 4, 0); + wm_tool_get_crc32((unsigned char *)&fbooter, sizeof(wm_tool_firmware_booter_t) - 4, 0); // 4:byte alignment fbooter.hd_checksum = wm_tool_file_crc; /* write image's header to output file */ @@ -3475,14 +3474,14 @@ static int wm_tool_pack_gz_image(const char *gzbin, const char *outfile) fpbin = fopen(gzbin, "rb"); if (fpbin == NULL) { wm_tool_printf("can not open input file [%s].\r\n", gzbin); - return -2; + return -2; // -2:byte alignment } fpimg = fopen(outfile, "wb+"); if (fpimg == NULL) { wm_tool_printf("create img file error: [%s].\r\n", outfile); fclose(fpbin); - return -3; + return -3; // -3:byte alignment } /* --------deal with upgrade image's CRC begin---- */ @@ -3490,8 +3489,8 @@ static int wm_tool_pack_gz_image(const char *gzbin, const char *outfile) while (!feof(fpbin)) { memset(buf, 0, sizeof(buf)); readlen = fread(buf, 1, WM_TOOL_ONCE_READ_LEN, fpbin); - if (readlen % 4 != 0) { - patch = 4 - readlen%4; + if (readlen % 4 != 0) { // 4:byte alignment + patch = 4 - readlen % 4; // 4:byte alignment readlen += patch; } filelen += readlen; @@ -3562,22 +3561,22 @@ static int wm_tool_pack_dbg_image(const char *image, const char *outfile) fpimg = fopen(image, "rb"); if (fpimg == NULL) { wm_tool_printf("open img file error: [%s].\r\n", image); - return -4; + return -4; // -4:byte alignment } magic_word = 0; - readlen = fread(&magic_word, 1, 4, fpimg); + readlen = fread(&magic_word, 1, 4, fpimg); // 4:size if (magic_word != WM_TOOL_IMG_HEAD_MAGIC_NO) { wm_tool_printf("input [%s] file magic error.\n", image); fclose(fpimg); - return -5; + return -5; // -5:byte alignment } fout = fopen(outfile, "wb+"); if (fout == NULL) { wm_tool_printf("create img file error [%s].\r\n", outfile); fclose(fpimg); - return -6; + return -6; // -6:byte alignment } appimg_len = wm_tool_get_file_size(image); @@ -3631,7 +3630,7 @@ static int wm_tool_pack_fls(const char *image, const char *outfile) fpsec = fopen(wm_tool_secboot_image, "rb"); if (fpsec == NULL) { wm_tool_printf("can not open input file [%s].\r\n", wm_tool_secboot_image); - return -2; + return -2; // -2:byte alignment } magic_word = 0; @@ -3639,14 +3638,14 @@ static int wm_tool_pack_fls(const char *image, const char *outfile) if (magic_word != WM_TOOL_IMG_HEAD_MAGIC_NO) { wm_tool_printf("input [%s] file magic error.\r\n", wm_tool_secboot_image); fclose(fpsec); - return -3; + return -3; // -3:byte alignment } fpimg = fopen(image, "rb"); if (fpimg == NULL) { wm_tool_printf("open img file error [%s].\r\n", image); fclose(fpsec); - return -4; + return -4; // -4:byte alignment } magic_word = 0; @@ -3655,7 +3654,7 @@ static int wm_tool_pack_fls(const char *image, const char *outfile) wm_tool_printf("input [%s] file magic error.\r\n", image); fclose(fpsec); fclose(fpimg); - return -5; + return -5; // -5:byte alignment } fout = fopen(outfile, "wb+"); @@ -3663,7 +3662,7 @@ static int wm_tool_pack_fls(const char *image, const char *outfile) wm_tool_printf("create img file error [%s].\r\n", outfile); fclose(fpsec); fclose(fpimg); - return -6; + return -6; // -6:byte alignment } fseek(fpsec, 0, SEEK_SET); @@ -3945,12 +3944,12 @@ static int wm_tool_uart_set_speed(int speed) return SetCommState(wm_tool_uart_handle, &cfg) ? 0 : -1; } else { - return -3; + return -3; // -4:byte alignment } } } - return -2; + return -2; // -2:byte alignment } static void wm_tool_uart_clear(void) @@ -4244,7 +4243,7 @@ static int wm_tool_uart_open(const char *device) tty.c_cflag |= CLOCAL | CREAD; tty.c_cflag &= ~CRTSCTS; tty.c_cc[VMIN] = 1; - tty.c_cc[VTIME] = 5; + tty.c_cc[VTIME] = 5; // 5:byte alignment /* have no software flow control */ tty.c_iflag &= ~(IXON|IXOFF|IXANY); @@ -4377,7 +4376,7 @@ static int wm_tool_show_log_from_serial(void) } else if (WM_TOOL_SHOW_LOG_HEX == wm_tool_show_log_type) { for (i = 0; i < ret; i++, j++) { wm_tool_printf("%02X ", buf[i]); - if ((j + 1) % 16 == 0) { + if ((j + 1) % 16 == 0) { // 16:byte alignment wm_tool_printf("\r\n"); } } @@ -4398,13 +4397,13 @@ static int wm_tool_set_wifi_chip_speed(int speed) { int ret; - if (speed == 2000000) { + if (speed == 2000000) { // 2000000:value of speed ret = wm_tool_uart_write(wm_tool_chip_cmd_b2000000, sizeof(wm_tool_chip_cmd_b2000000)); - } else if (speed == 1000000) { + } else if (speed == 1000000) { // 1000000:value of speed ret = wm_tool_uart_write(wm_tool_chip_cmd_b1000000, sizeof(wm_tool_chip_cmd_b1000000)); - } else if (speed == 921600) { + } else if (speed == 921600) { // 921600:value of speed ret = wm_tool_uart_write(wm_tool_chip_cmd_b921600, sizeof(wm_tool_chip_cmd_b921600)); - } else if (speed == 460800) { + } else if (speed == 460800) { // 460800:value of speed ret = wm_tool_uart_write(wm_tool_chip_cmd_b460800, sizeof(wm_tool_chip_cmd_b460800)); } else { ret = wm_tool_uart_write(wm_tool_chip_cmd_b115200, sizeof(wm_tool_chip_cmd_b115200)); @@ -4419,9 +4418,9 @@ static int wm_tool_send_esc2uart(int ms) int err = 0; unsigned char esc_key = 27; - for (i = 0; i < (ms / 10); i++) { + for (i = 0; i < (ms / 10); i++) { // 10:byte alignment err = wm_tool_uart_write(&esc_key, 1); - wm_tool_delay_ms(10); /* 10-50ms */ + wm_tool_delay_ms(10); // 10:10ms } return err; @@ -4459,9 +4458,9 @@ static int wm_tool_erase_image(wm_tool_dl_erase_e type) } } else { wm_tool_printf("erase error, errno = %d.\r\n", errno); - return -2; + return -2; // -2:byte alignment } - } while (cnt < 3); + } while (cnt < 3); // 3:loop condition wm_tool_uart_set_block(0); @@ -4492,7 +4491,7 @@ static int wm_tool_query_mac(void) if (offset >= len) { macstr[len - 1] = '\0'; /* \n -> 0 */ if (strstr(macstr, "Mac:")) { - err = wm_tool_str_to_hex_array(macstr + strlen("MAC:"), 6, macaddr); + err = wm_tool_str_to_hex_array(macstr + strlen("MAC:"), 6, macaddr); // 6:cnt } else { err = 0; } @@ -4530,7 +4529,7 @@ static int wm_tool_xmodem_download(const char *image) unsigned char ack_id; int sndlen; int total_size; - int ret = -111; + int ret = -111; // -111:byte alignment int percent = 0; int curImgLen = 0; wm_tool_firmware_booter_t fbooter; @@ -4576,8 +4575,8 @@ static int wm_tool_xmodem_download(const char *image) WM_TOOL_DBG_PRINT("packet_data_offset = %d, packet_data_len = %d\r\n", \ packet_data_offset, packet_data_len); WM_TOOL_DBG_PRINT("header %x %x %x %x\r\n", packet_data[packet_data_offset], \ - packet_data[packet_data_offset+1], packet_data[packet_data_offset+2], \ - packet_data[packet_data_offset+3]); + packet_data[packet_data_offset + 1], packet_data[packet_data_offset + 2], \ + packet_data[packet_data_offset + 3]); memmove(packet_data, packet_data + packet_data_offset, packet_data_len); WM_TOOL_DBG_PRINT("header %x %x %x %x\r\n", packet_data[0], packet_data[1], packet_data[2], packet_data[3]); @@ -4595,8 +4594,8 @@ static int wm_tool_xmodem_download(const char *image) memcpy(&fbooter, packet_data, sizeof(wm_tool_firmware_booter_t)); curImgLen = fbooter.run_img_len; curImgLen += sizeof(wm_tool_firmware_booter_t); - if ((fbooter.img_type & 256) > 0) { - curImgLen += 128; + if ((fbooter.img_type & 256) > 0) { // 256:byte alignment + curImgLen += 128; // 128:byte alignment } WM_TOOL_DBG_PRINT("curImgLen %d\r\n", curImgLen); } @@ -4614,18 +4613,19 @@ static int wm_tool_xmodem_download(const char *image) memset(&frame_data[0], 0, sizeof(frame_data)); frame_data[0] = XMODEM_HEAD; frame_data[1] = (char)pack_counter; - frame_data[2] = (char)(255 - frame_data[1]); + frame_data[2] = (char)(255 - frame_data[1]); // 255:byte alignment, 2:array element for (i = 0; i < read_number; i++) { - frame_data[i + 3] = packet_data[i]; + frame_data[i + 3] = packet_data[i]; // 3:byte alignment } crc_value = wm_tool_get_crc16(&frame_data[3], XMODEM_DATA_SIZE); - frame_data[XMODEM_DATA_SIZE + 3]=(unsigned char)(crc_value >> 8); - frame_data[XMODEM_DATA_SIZE + 4]=(unsigned char)(crc_value); + frame_data[XMODEM_DATA_SIZE + 3] = + (unsigned char)(crc_value >> 8); // 8:byte alignment, 3:byte alignment + frame_data[XMODEM_DATA_SIZE + 4] = (unsigned char)(crc_value); // 4:byte alignment - write_number = wm_tool_uart_write(frame_data, XMODEM_DATA_SIZE + 5); + write_number = wm_tool_uart_write(frame_data, XMODEM_DATA_SIZE + 5); // 5:byte alignment if (write_number <= 0) { wm_tool_printf("write serial error, errno = %d.\r\n", errno); } @@ -4638,13 +4638,13 @@ static int wm_tool_xmodem_download(const char *image) } else { if (ack_id == XMODEM_ACK) { int start_percent = 0; - int step = 10; + int step = 10; // 10:byte alignment WM_TOOL_DBG_PRINT("Ok!\r\n"); if (sndlen * step / total_size > percent) { percent = sndlen * step / total_size; wm_tool_printf("#"); } - if (sndlen % 10240 == 0) { + if (sndlen % 10240 == 0) { // 10240:byte alignment } } else { WM_TOOL_DBG_PRINT("error = %x!\r\n", ack_id); @@ -4678,7 +4678,7 @@ static int wm_tool_xmodem_download(const char *image) ret = 0; } else { - wm_tool_delay_ms(100); + wm_tool_delay_ms(100); // 100:100ms wm_tool_uart_clear(); } } @@ -4686,13 +4686,13 @@ static int wm_tool_xmodem_download(const char *image) } case XMODEM_NAK: { - if (retry_num++ > 100) { + if (retry_num++ > 100) { // 100:retry_num WM_TOOL_DBG_PRINT("retry too many times, quit!\r\n"); wm_tool_printf("download firmware timeout.\r\n"); complete = 1; } else { - write_number = wm_tool_uart_write(frame_data, XMODEM_DATA_SIZE + 5); + write_number = wm_tool_uart_write(frame_data, XMODEM_DATA_SIZE + 5); // 5:byte alignment if (write_number <= 0) { wm_tool_printf("write serial error, errno = %d.\r\n", errno); } @@ -4746,7 +4746,7 @@ static int wm_tool_download_firmware(void) } /* In some cases, setting the serial port initialization setting requires a delay. */ - wm_tool_delay_ms(500); + wm_tool_delay_ms(500); // 500:500ms wm_tool_printf("serial connected.\r\n"); @@ -4759,7 +4759,7 @@ static int wm_tool_download_firmware(void) if (ret <= 0) { wm_tool_printf("reset error.\r\n"); wm_tool_uart_close(); - return -4; + return -4; // -4:byte alignment } if (wm_tool_normal_serial_rate != WM_TOOL_DEFAULT_BAUD_RATE) { @@ -4768,21 +4768,21 @@ static int wm_tool_download_firmware(void) } else if (WM_TOOL_DL_ACTION_RTS == wm_tool_dl_action) { ret = wm_tool_uart_set_dtr(0); ret |= wm_tool_uart_set_rts(1); - wm_tool_delay_ms(50); + wm_tool_delay_ms(50); // 50:50ms ret |= wm_tool_uart_set_dtr(1); ret |= wm_tool_uart_set_rts(0); - wm_tool_delay_ms(50); + wm_tool_delay_ms(50); // 50:50ms ret |= wm_tool_uart_set_dtr(0); if (ret < 0) { wm_tool_printf("set rts to reboot error.\r\n"); wm_tool_uart_close(); - return -5; + return -5; // -5:byte alignment } } wm_tool_printf("wait serial sync..."); - wm_tool_send_esc2uart(500); /* used for delay */ + wm_tool_send_esc2uart(500); // 500:used for delay start = time(NULL); @@ -4798,7 +4798,7 @@ static int wm_tool_download_firmware(void) cnt = 0; } } else { - wm_tool_send_esc2uart(30); + wm_tool_send_esc2uart(30); // 30:30ms } end = time(NULL); @@ -4807,18 +4807,18 @@ static int wm_tool_download_firmware(void) wm_tool_printf("."); timeout++; - if ((timeout >= (WM_TOOL_DOWNLOAD_TIMEOUT_SEC / 10)) && note) { + if ((timeout >= (WM_TOOL_DOWNLOAD_TIMEOUT_SEC / 10)) && note) { // 10:byte alignment wm_tool_printf("\r\nplease manually reset the device.\r\n"); note = 0; } else if (timeout > WM_TOOL_DOWNLOAD_TIMEOUT_SEC) { wm_tool_uart_close(); wm_tool_printf("\r\nserial sync timeout.\r\n"); - return -6; + return -6; // -6:byte alignment } start = time(NULL); } - } while (cnt < 3); + } while (cnt < 3); // 3:loop condition wm_tool_printf("\r\nserial sync sucess.\r\n"); @@ -4845,7 +4845,7 @@ static int wm_tool_download_firmware(void) if (wm_tool_download_serial_rate != WM_TOOL_DEFAULT_BAUD_RATE) { ret = wm_tool_set_wifi_chip_speed(wm_tool_download_serial_rate); if (ret > 0) { - wm_tool_delay_ms(1 * 1000); + wm_tool_delay_ms(1 * 1000); // 1000:ms wm_tool_uart_set_speed(wm_tool_download_serial_rate); } } @@ -4853,9 +4853,9 @@ static int wm_tool_download_firmware(void) ret = wm_tool_xmodem_download(wm_tool_download_image); if (wm_tool_download_serial_rate != WM_TOOL_DEFAULT_BAUD_RATE) { - wm_tool_delay_ms(1 * 1000); + wm_tool_delay_ms(1 * 1000); // 1000:ms wm_tool_set_wifi_chip_speed(WM_TOOL_DEFAULT_BAUD_RATE); - wm_tool_delay_ms(1 * 1000); + wm_tool_delay_ms(1 * 1000); // 1000:ms } if (!ret) { @@ -4863,10 +4863,10 @@ static int wm_tool_download_firmware(void) if (WM_TOOL_DL_ACTION_RTS == wm_tool_dl_action) { /* auto reset */ wm_tool_uart_set_dtr(0); wm_tool_uart_set_rts(1); - wm_tool_delay_ms(50); + wm_tool_delay_ms(50); // 50:ms wm_tool_uart_set_dtr(1); wm_tool_uart_set_rts(0); - wm_tool_delay_ms(50); + wm_tool_delay_ms(50); // 50:ms wm_tool_uart_set_dtr(0); } else { wm_tool_printf("please manually reset the device.\r\n"); diff --git a/wm800/board/include/arch/xt804/csi_core/core_804.h b/wm800/board/include/arch/xt804/csi_core/core_804.h index 67bfc3b..c0a59ac 100755 --- a/wm800/board/include/arch/xt804/csi_core/core_804.h +++ b/wm800/board/include/arch/xt804/csi_core/core_804.h @@ -763,7 +763,7 @@ __STATIC_INLINE void csi_vic_disable_sirq(int32_t IRQn) __STATIC_INLINE uint32_t csi_vic_get_enabled_irq(int32_t IRQn) { int32_t IRQn_tmp = IRQn; - IRQn &= 0x7FUL; + IRQn_tmp &= 0x7FUL; return ((uint32_t)(((VIC->ISER[_IR_IDX(IRQn_tmp)] & (1UL << (((uint32_t)(int32_t)IRQn_tmp % 32) & 0x7FUL))) != 0UL) ? 1UL : 0UL)); // 32:byte alignment @@ -1454,12 +1454,12 @@ __STATIC_INLINE void csi_mpu_config_region(uint32_t idx, uint32_t base_addr, reg __set_PRSR(prsr.w); if (size != REGION_SIZE_4KB) { - pacr.w &= ~(((1u << (size -11)) - 1) << 12); // 12:byte alignment + pacr.w &= ~(((1u << (size -11)) - 1) << 12); // 12:byte alignment, 11:byte alignment } pacr.b.size = size; - capr.w &= ~((0x1 << idx) | (0x3 << (idx * 2 + 8)) | (0x1 << (idx + 24))); // 12:byte alignment + capr.w &= ~((0x1 << idx) | (0x3 << (idx * 2 + 8)) | (0x1 << (idx + 24))); // 2:byte, 8:byte, 24:byte capr.w = (capr.w | (attr.nx << idx) | (attr.ap << (idx * 2 + 8)) | // 2:byte , 8:byte alignment (attr.s << (idx + 24))); // 24:byte alignment pacr.w &= ~(((1u << (size -11)) - 1) << 12); // 12:byte alignment, 11:byte alignment diff --git a/wm800/board/include/wm_wifi_api.h b/wm800/board/include/wm_wifi_api.h index 5b66cac..770ed26 100755 --- a/wm800/board/include/wm_wifi_api.h +++ b/wm800/board/include/wm_wifi_api.h @@ -134,9 +134,12 @@ extern "C" { * * default max num of station.CNcomment:默认支持的station最大个数.CNend */ -#define WIFI_DEFAULT_MAX_NUM_STA 6#ifdef __cplusplus +#define WIFI_DEFAULT_MAX_NUM_STA 6 + +#ifdef __cplusplus #if __cplusplus } #endif +#endif #endif /* end of hi_wifi_api.h */ \ No newline at end of file diff --git a/wm800/board/platform/arch/xt804/libc/libc_port.c b/wm800/board/platform/arch/xt804/libc/libc_port.c index a418cde..1d14d61 100755 --- a/wm800/board/platform/arch/xt804/libc/libc_port.c +++ b/wm800/board/platform/arch/xt804/libc/libc_port.c @@ -202,9 +202,9 @@ static inline int digitval(int ch) if (ch >= '0' && ch <= '9') { return ch-'0'; } else if (ch >= 'A' && ch <= 'Z') { - return ch-'A'+10; + return ch-'A' + 10; // 10:byte alignment } else if (ch >= 'a' && ch <= 'z') { - return ch-'a'+10; + return ch-'a' + 10; // 10:byte alignment } else { return -1; } @@ -217,50 +217,51 @@ uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n) int d; int base_tmp = base; size_t n_tmp = n; + const char *nptr_tmp = nptr; - while (n_tmp && isspace((unsigned char)*nptr)) { - nptr++; + while (n_tmp && isspace((unsigned char)*nptr_tmp)) { + nptr_tmp++; n_tmp--; } /* Single optional + or - */ - if (n_tmp && *nptr == '-') { + if (n_tmp && *nptr_tmp == '-') { minus = 1; - nptr++; + nptr_tmp++; n_tmp--; - } else if (n_tmp && *nptr == '+') { - nptr++; + } else if (n_tmp && *nptr_tmp == '+') { + nptr_tmp++; } if (base_tmp == 0) { - if (n_tmp >= 2 && nptr[0] == '0' && // 2:byte alignment - (nptr[1] == 'x' || nptr[1] == 'X')) { + if (n_tmp >= 2 && nptr_tmp[0] == '0' && // 2:byte alignment + (nptr_tmp[1] == 'x' || nptr_tmp[1] == 'X')) { n_tmp -= 2; // 2:byte alignment - nptr += 2; // 2:byte alignment + nptr_tmp += 2; // 2:byte alignment base_tmp = 16; // 16:byte alignment - } else if (n_tmp >= 1 && nptr[0] == '0') { + } else if (n_tmp >= 1 && nptr_tmp[0] == '0') { n_tmp--; - nptr++; + nptr_tmp++; base_tmp = 8; // 8:byte alignment } else { base_tmp = 10; // 10:byte alignment } } else if (base_tmp == 16) { // 16:byte alignment - if (n_tmp >= 2 && nptr[0] == '0' && - (nptr[1] == 'x' || nptr[1] == 'X')) { + if (n_tmp >= 2 && nptr_tmp[0] == '0' && + (nptr_tmp[1] == 'x' || nptr_tmp[1] == 'X')) { n_tmp -= 2; // 2:byte alignment - nptr += 2; // 2:byte alignment + nptr_tmp += 2; // 2:byte alignment } } - while (n_tmp && (d = digitval(*nptr)) >= 0 && d < base_tmp) { - v = v*base_tmp + d; + while (n_tmp && (d = digitval(*nptr_tmp)) >= 0 && d < base_tmp) { + v = v * base_tmp + d; n_tmp--; - nptr++; + nptr_tmp++; } if (endptr) { - *endptr = (char *)nptr; + *endptr = (char *)nptr_tmp; } return minus ? -v : v; @@ -301,10 +302,11 @@ enum bail { static inline const char *skipspace(const char *p) { - while (isspace((unsigned char)*p)) { - p++; + const char *p_tmp = p; + while (isspace((unsigned char)*p_tmp)) { + p_tmp++; } - return p; + return p_tmp; } #undef set_bit @@ -687,7 +689,8 @@ static inline void _out_null(char character, void* buffer, size_t idx, size_t ma static inline unsigned int _strnlen_s(const char* str, size_t maxsize) { const char* s; - for (s = str; *s && maxsize--; ++s) { + size_t maxsize_tmp = maxsize; + for (s = str; *s && maxsize_tmp--; ++s) { } return (unsigned int)(s - str); } @@ -714,27 +717,29 @@ static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen const char* buf, size_t len, unsigned int width, unsigned int flags) { const size_t start_idx = idx; + size_t idx_tmp = idx; + size_t len_tmp = len; // pad spaces up to given width if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) { - for (size_t i = len; i < width; i++) { - out(' ', buffer, idx++, maxlen); + for (size_t i = len_tmp; i < width; i++) { + out(' ', buffer, idx_tmp++, maxlen); } } // reverse string - while (len) { - out(buf[--len], buffer, idx++, maxlen); + while (len_tmp) { + out(buf[--len_tmp], buffer, idx_tmp++, maxlen); } // append pad spaces up to given width if (flags & FLAGS_LEFT) { - while (idx - start_idx < width) { - out(' ', buffer, idx++, maxlen); + while (idx_tmp - start_idx < width) { + out(' ', buffer, idx_tmp++, maxlen); } } - return idx; + return idx_tmp; } // internal itoa format @@ -870,37 +875,39 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, char buf[PRINTF_FTOA_BUFFER_SIZE]; size_t len = 0U; double diff = 0.0; + double value_tmp = value; + unsigned int width_tmp = width; // powers of 10 static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; // test for special values - if (value != value) { - return _out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags); + if (value_tmp != value_tmp) { + return _out_rev(out, buffer, idx, maxlen, "nan", 3, width_tmp, flags); // 3:len } - if (value < -DBL_MAX) { - return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags); + if (value_tmp < -DBL_MAX) { + return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width_tmp, flags); // 4:len } - if (value > DBL_MAX) { + if (value_tmp > DBL_MAX) { return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", - (flags & FLAGS_PLUS) ? 4U : 3U, width, flags); + (flags & FLAGS_PLUS) ? 4U : 3U, width_tmp, flags); } // test for very large values // standard printf behavior is to print EVERY whole number digit -- // which could be 100s of characters overflowing your buffers == bad - if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) { + if ((value_tmp > PRINTF_MAX_FLOAT) || (value_tmp < -PRINTF_MAX_FLOAT)) { #if defined(PRINTF_SUPPORT_EXPONENTIAL) - return _etoa(out, buffer, idx, maxlen, value, prec_tmp, width, flags); + return _etoa(out, buffer, idx, maxlen, value_tmp, prec_tmp, width_tmp, flags); #else return 0U; #endif } // test for negative bool negative = false; - if (value < 0) { + if (value_tmp < 0) { negative = true; - value = 0 - value; + value_tmp = 0 - value_tmp; } // set default precision, if not set explicitly @@ -913,8 +920,8 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, prec_tmp--; } - int whole = (int)value; - double tmp = (value - whole) * pow10[prec_tmp]; + int whole = (int)value_tmp; + double tmp = (value_tmp - whole) * pow10[prec_tmp]; unsigned long frac = (unsigned long)tmp; diff = tmp - frac; @@ -932,7 +939,7 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, } if (prec_tmp == 0U) { - diff = value - (double)whole; + diff = value_tmp - (double)whole; if ((diff > 0.5) && (whole & 1)) { // exactly 0.5 and ODD, then round up // 1.5 -> 2, but 2.5 -> 2 @@ -968,10 +975,10 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, // pad leading zeros if (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) { - if (width && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { - width--; + if (width_tmp && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { + width_tmp--; } - while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) { + while ((len < width_tmp) && (len < PRINTF_FTOA_BUFFER_SIZE)) { buf[len++] = '0'; } } @@ -986,7 +993,7 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, } } - return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags); + return _out_rev(out, buffer, idx, maxlen, buf, len, width_tmp, flags); } #if defined(PRINTF_SUPPORT_EXPONENTIAL) @@ -995,19 +1002,23 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d unsigned int prec, unsigned int width, unsigned int flags) { unsigned int prec_tmp = prec; + double value_tmp = value; + unsigned int flags_tmp = flags; + size_t idx_tmp = idx; + char* buffer_tmp = buffer; // check for NaN and special values - if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) { - return _ftoa(out, buffer, idx, maxlen, value, prec_tmp, width, flags); + if ((value_tmp != value_tmp) || (value_tmp > DBL_MAX) || (value_tmp < -DBL_MAX)) { + return _ftoa(out, buffer_tmp, idx_tmp, maxlen, value_tmp, prec_tmp, width, flags_tmp); } // determine the sign - const bool negative = value < 0; + const bool negative = value_tmp < 0; if (negative) { - value = -value; + value_tmp = -value_tmp; } // default precision - if (!(flags & FLAGS_PRECISION)) { + if (!(flags_tmp & FLAGS_PRECISION)) { prec_tmp = PRINTF_DEFAULT_FLOAT_PRECISION; } @@ -1018,7 +1029,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d double F; } conv; - conv.F = value; + conv.F = value_tmp; int exp2 = (int)((conv.U >> 52U) & 0x07FFU) - 1023; // effectively log2 conv.U = (conv.U & ((1ULL << 52U) - 1U)) | (1023ULL << 52U); // drop the exponent so conv.F is now in [1,2) // now approximate log10 from the log2 integer part and an expansion of ln around 1.5 @@ -1034,7 +1045,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + // 2:byte alignment, 6:byte alignment (z2 / (10 + z2 / 14))))); // 10:byte alignment, 14:byte alignment // correct for rounding errors - if (value < conv.F) { + if (value_tmp < conv.F) { expval--; conv.F /= 10; // 10:byte alignment } @@ -1043,21 +1054,21 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U; // in "%g" mode, "prec" is the number of *significant figures* not decimals - if (flags & FLAGS_ADAPT_EXP) { + if (flags_tmp & FLAGS_ADAPT_EXP) { // do we want to fall-back to "%f" mode? - if ((value >= 1e-4) && (value < 1e6)) { + if ((value_tmp >= 1e-4) && (value_tmp < 1e6)) { if ((int)prec_tmp > expval) { prec_tmp = (unsigned)((int)prec_tmp - expval - 1); } else { prec_tmp = 0; } - flags |= FLAGS_PRECISION; // make sure _ftoa respects precision + flags_tmp |= FLAGS_PRECISION; // make sure _ftoa respects precision // no characters in exponent minwidth = 0U; expval = 0; } else { // we use one sigfig for the whole part - if ((prec_tmp > 0) && (flags & FLAGS_PRECISION)) { + if ((prec_tmp > 0) && (flags_tmp & FLAGS_PRECISION)) { --prec_tmp; } } @@ -1072,35 +1083,36 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d // not enough characters, so go back to default sizing fwidth = 0U; } - if ((flags & FLAGS_LEFT) && minwidth) { + if ((flags_tmp & FLAGS_LEFT) && minwidth) { // if we're padding on the right, DON'T pad the floating part fwidth = 0U; } // rescale the float value if (expval) { - value /= conv.F; + value_tmp /= conv.F; } // output the floating part - const size_t start_idx = idx; - idx = _ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec_tmp, fwidth, flags & ~FLAGS_ADAPT_EXP); + const size_t start_idx = idx_tmp; + idx_tmp = _ftoa(out, buffer_tmp, idx_tmp, maxlen, + negative ? -value_tmp : value_tmp, prec_tmp, fwidth, flags_tmp & ~FLAGS_ADAPT_EXP); // output the exponent part if (!prec_tmp && minwidth) { // output the exponential symbol - out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen); + out((flags_tmp & FLAGS_UPPERCASE) ? 'E' : 'e', buffer_tmp, idx_tmp++, maxlen); // output the exponent value - idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, - expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS); + idx_tmp = _ntoa_long(out, buffer_tmp, idx_tmp, maxlen, (expval < 0) ? -expval : expval, + expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS); // might need to right-pad spaces - if (flags & FLAGS_LEFT) { - while (idx - start_idx < width) { - out(' ', buffer, idx++, maxlen); + if (flags_tmp & FLAGS_LEFT) { + while (idx_tmp - start_idx < width) { + out(' ', buffer_tmp, idx_tmp++, maxlen); } } } - return idx; + return idx_tmp; } #endif // PRINTF_SUPPORT_EXPONENTIAL #endif // PRINTF_SUPPORT_FLOAT @@ -1110,42 +1122,44 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const { unsigned int flags, width, precision, n; size_t idx = 0U; + out_fct_type out_tmp = out; + const char* format_tmp = format; if (!buffer) { // use null output function - out = _out_null; + out_tmp = _out_null; } - while (*format) { + while (*format_tmp) { // format specifier? %[flags][width][.precision][length] - if (*format != '%') { + if (*format_tmp != '%') { // no - out(*format, buffer, idx++, maxlen); - format++; + out_tmp(*format_tmp, buffer, idx++, maxlen); + format_tmp++; continue; } else { // yes, evaluate it - format++; + format_tmp++; } // evaluate flags flags = 0U; do { - switch (*format) { - case '0': flags |= FLAGS_ZEROPAD; format++; n = 1U; break; - case '-': flags |= FLAGS_LEFT; format++; n = 1U; break; - case '+': flags |= FLAGS_PLUS; format++; n = 1U; break; - case ' ': flags |= FLAGS_SPACE; format++; n = 1U; break; - case '#': flags |= FLAGS_HASH; format++; n = 1U; break; + switch (*format_tmp) { + case '0': flags |= FLAGS_ZEROPAD; format_tmp++; n = 1U; break; + case '-': flags |= FLAGS_LEFT; format_tmp++; n = 1U; break; + case '+': flags |= FLAGS_PLUS; format_tmp++; n = 1U; break; + case ' ': flags |= FLAGS_SPACE; format_tmp++; n = 1U; break; + case '#': flags |= FLAGS_HASH; format_tmp++; n = 1U; break; default : n = 0U; break; } } while (n); // evaluate width field width = 0U; - if (_is_digit(*format)) { - width = _atoi(&format); - } else if (*format == '*') { + if (_is_digit(*format_tmp)) { + width = _atoi(&format_tmp); + } else if (*format_tmp == '*') { const int w = va_arg(va, int); if (w < 0) { flags |= FLAGS_LEFT; // reverse padding @@ -1153,61 +1167,61 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const } else { width = (unsigned int)w; } - format++; + format_tmp++; } // evaluate precision field precision = 0U; - if (*format == '.') { + if (*format_tmp == '.') { flags |= FLAGS_PRECISION; - format++; - if (_is_digit(*format)) { - precision = _atoi(&format); - } else if (*format == '*') { + format_tmp++; + if (_is_digit(*format_tmp)) { + precision = _atoi(&format_tmp); + } else if (*format_tmp == '*') { const int prec = (int)va_arg(va, int); precision = prec > 0 ? (unsigned int)prec : 0U; - format++; + format_tmp++; } } // evaluate length field - switch (*format) { + switch (*format_tmp) { case 'l' : flags |= FLAGS_LONG; - format++; - if (*format == 'l') { + format_tmp++; + if (*format_tmp == 'l') { flags |= FLAGS_LONG_LONG; - format++; + format_tmp++; } break; case 'h' : flags |= FLAGS_SHORT; - format++; - if (*format == 'h') { + format_tmp++; + if (*format_tmp == 'h') { flags |= FLAGS_CHAR; - format++; + format_tmp++; } break; #if defined(PRINTF_SUPPORT_PTRDIFF_T) case 't' : flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); - format++; + format_tmp++; break; #endif case 'j' : flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); - format++; + format_tmp++; break; case 'z' : flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); - format++; + format_tmp++; break; default : break; } // evaluate specifier - switch (*format) { + switch (*format_tmp) { case 'd' : case 'i' : case 'u' : @@ -1217,23 +1231,23 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const case 'b' : { // set the base unsigned int base; - if (*format == 'x' || *format == 'X') { + if (*format_tmp == 'x' || *format_tmp == 'X') { base = 16U; - } else if (*format == 'o') { + } else if (*format_tmp == 'o') { base = 8U; - } else if (*format == 'b') { + } else if (*format_tmp == 'b') { base = 2U; } else { base = 10U; flags &= ~FLAGS_HASH; // no hash for dec format } // uppercase - if (*format == 'X') { + if (*format_tmp == 'X') { flags |= FLAGS_UPPERCASE; } // no plus or space flag for u, x, X, o, b - if ((*format != 'i') && (*format != 'd')) { + if ((*format_tmp != 'i') && (*format_tmp != 'd')) { flags &= ~(FLAGS_PLUS | FLAGS_SPACE); } @@ -1243,67 +1257,67 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const } // convert the integer - if ((*format == 'i') || (*format == 'd')) { + if ((*format_tmp == 'i') || (*format_tmp == 'd')) { // signed if (flags & FLAGS_LONG_LONG) { #if defined(PRINTF_SUPPORT_LONG_LONG) const long long value = va_arg(va, long long); - idx = _ntoa_long_long(out, buffer, idx, maxlen, + idx = _ntoa_long_long(out_tmp, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); #endif } else if (flags & FLAGS_LONG) { const long value = va_arg(va, long); - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), + idx = _ntoa_long(out_tmp, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); } else { const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : \ (flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int); - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), + idx = _ntoa_long(out_tmp, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); } } else { // unsigned if (flags & FLAGS_LONG_LONG) { #if defined(PRINTF_SUPPORT_LONG_LONG) - idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), + idx = _ntoa_long_long(out_tmp, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags); #endif } else if (flags & FLAGS_LONG) { - idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), + idx = _ntoa_long(out_tmp, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags); } else { const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : \ (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : \ va_arg(va, unsigned int); - idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags); + idx = _ntoa_long(out_tmp, buffer, idx, maxlen, value, false, base, precision, width, flags); } } - format++; + format_tmp++; break; } #if defined(PRINTF_SUPPORT_FLOAT) case 'f' : case 'F' : - if (*format == 'F') { + if (*format_tmp == 'F') { flags |= FLAGS_UPPERCASE; } - idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); - format++; + idx = _ftoa(out_tmp, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); + format_tmp++; break; #if defined(PRINTF_SUPPORT_EXPONENTIAL) case 'e': case 'E': case 'g': case 'G': - if ((*format == 'g')||(*format == 'G')) { + if ((*format_tmp == 'g')||(*format_tmp == 'G')) { flags |= FLAGS_ADAPT_EXP; } - if ((*format == 'E')||(*format == 'G')) { + if ((*format_tmp == 'E')||(*format_tmp == 'G')) { flags |= FLAGS_UPPERCASE; } - idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); - format++; + idx = _etoa(out_tmp, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); + format_tmp++; break; #endif // PRINTF_SUPPORT_EXPONENTIAL #endif // PRINTF_SUPPORT_FLOAT @@ -1312,18 +1326,18 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const // pre padding if (!(flags & FLAGS_LEFT)) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } // char output - out((char)va_arg(va, int), buffer, idx++, maxlen); + out_tmp((char)va_arg(va, int), buffer, idx++, maxlen); // post padding if (flags & FLAGS_LEFT) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } - format++; + format_tmp++; break; } @@ -1336,20 +1350,20 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const } if (!(flags & FLAGS_LEFT)) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } // string output while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) { - out(*(p++), buffer, idx++, maxlen); + out_tmp(*(p++), buffer, idx++, maxlen); } // post padding if (flags & FLAGS_LEFT) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } - format++; + format_tmp++; break; } @@ -1362,16 +1376,16 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const is_ll = true; } if (is_ll) { - idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), + idx = _ntoa_long_long(out_tmp, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags); } else { #endif - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), + idx = _ntoa_long(out_tmp, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, precision, width, flags); #if defined(PRINTF_SUPPORT_LONG_LONG) } #endif - format++; + format_tmp++; break; } @@ -1386,20 +1400,20 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const } if (!(flags & FLAGS_LEFT)) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } // string output while ((*pstr != 0) && (!(flags & FLAGS_PRECISION) || precision--)) { - out(*(pstr++), buffer, idx++, maxlen); + out_tmp(*(pstr++), buffer, idx++, maxlen); } // post padding if (flags & FLAGS_LEFT) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } - format++; + format_tmp++; break; } case 'v' : { @@ -1413,20 +1427,20 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const } if (!(flags & FLAGS_LEFT)) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } // string output while ((*pstr != 0) && (!(flags & FLAGS_PRECISION) || precision--)) { - out(*(pstr++), buffer, idx++, maxlen); + out_tmp(*(pstr++), buffer, idx++, maxlen); } // post padding if (flags & FLAGS_LEFT) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } - format++; + format_tmp++; break; } case 'V' : { @@ -1440,37 +1454,37 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const } if (!(flags & FLAGS_LEFT)) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } // string output while ((*pstr != 0) && (!(flags & FLAGS_PRECISION) || precision--)) { - out(*(pstr++), buffer, idx++, maxlen); + out_tmp(*(pstr++), buffer, idx++, maxlen); } // post padding if (flags & FLAGS_LEFT) { while (l++ < width) { - out(' ', buffer, idx++, maxlen); + out_tmp(' ', buffer, idx++, maxlen); } } - format++; + format_tmp++; break; } case '%' : - out('%', buffer, idx++, maxlen); - format++; + out_tmp('%', buffer, idx++, maxlen); + format_tmp++; break; default : - out(*format, buffer, idx++, maxlen); - format++; + out_tmp(*format_tmp, buffer, idx++, maxlen); + format_tmp++; break; } } // termination - out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen); + out_tmp((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen); // return written chars without terminating \0 return (int)idx; diff --git a/wm800/board/platform/common/utils/utils.c b/wm800/board/platform/common/utils/utils.c index abab758..3dade09 100755 --- a/wm800/board/platform/common/utils/utils.c +++ b/wm800/board/platform/common/utils/utils.c @@ -296,13 +296,14 @@ int strtohex(u32 *hex, char *str) int n; int i; u32 dd; + char *str_tmp = str; n = -1; i = 0; dd = 0; - while (*str) { - n = atohex(*str++); + while (*str_tmp) { + n = atohex(*str_tmp++); if (n < 0) {return -1;} dd = (dd<<4) + n; if (++i > 8) {return -1;} @@ -318,15 +319,16 @@ int strtohexarray(u8 array[], int cnt, char *str) u8 tmp; u8 *des; int cnt_tmp = cnt; + char *str_tmp = str; des = array; while (cnt_tmp-- > 0) { - int hex = atohex(*str++); + int hex = atohex(*str_tmp++); if (hex < 0) { return -1; } else {tmp = (hex << 4) & 0xf0;} - hex = atohex(*str++); + hex = atohex(*str_tmp++); if (hex < 0) { return -1; } else { @@ -336,7 +338,7 @@ int strtohexarray(u8 array[], int cnt, char *str) *des++ = (u8) tmp; } - return ((*str==0) ? 0 : -1); + return ((*str_tmp==0) ? 0 : -1); } int strtoip(u32 *ipadr, char * str) @@ -542,9 +544,11 @@ void dumpUint32(char *name, uint32_t* buffer, int len) int strcasecmp(const char *s1, const char *s2) { - while (*s1 && *s2) { - char a = *s1++; - char b = *s2++; + const char *s1_tmp = s1; + const char *s2_tmp = s2; + while (*s1_tmp && *s2_tmp) { + char a = *s1_tmp++; + char b = *s2_tmp++; if (a == b) { continue; diff --git a/wm800/board/src/bt/blehost/nimble/host/mesh/include/mesh/glue.h b/wm800/board/src/bt/blehost/nimble/host/mesh/include/mesh/glue.h index b4a3462..a02b275 100755 --- a/wm800/board/src/bt/blehost/nimble/host/mesh/include/mesh/glue.h +++ b/wm800/board/src/bt/blehost/nimble/host/mesh/include/mesh/glue.h @@ -348,13 +348,14 @@ static inline void net_buf_simple_restore(struct os_mbuf *buf, static inline void sys_memcpy_swap(void *dst, const void *src, size_t length) { size_t Length = length; + const void *src_tmp = src; __ASSERT(((src < dst && (src + Length) <= dst) || (src > dst && (dst + Length) <= src)), "Source and destination buffers must not overlap"); - src += Length - 1; + src_tmp += Length - 1; for (; Length > 0; Length--) { - *((u8_t *)dst++) = *((u8_t *)src--); + *((u8_t *)dst++) = *((u8_t *)src_tmp--); } } diff --git a/wm800/board/src/bt/blehost/nimble/host/mesh/src/crypto.c b/wm800/board/src/bt/blehost/nimble/host/mesh/src/crypto.c index cae2c36..abac15d 100755 --- a/wm800/board/src/bt/blehost/nimble/host/mesh/src/crypto.c +++ b/wm800/board/src/bt/blehost/nimble/host/mesh/src/crypto.c @@ -31,13 +31,14 @@ int bt_mesh_aes_cmac(const u8_t key[16], struct bt_mesh_sg *sg, struct tc_aes_ key_sched_struct sched; struct tc_cmac_struct state; + struct bt_mesh_sg *sg_tmp = sg; if (tc_cmac_setup(&state, key, &sched) == TC_CRYPTO_FAIL) { return -EIO; } - for (; sg_len_tmp; sg_len_tmp--, sg++) { - if (tc_cmac_update(&state, sg->data, sg->len) == TC_CRYPTO_FAIL) { + for (; sg_len_tmp; sg_len_tmp--, sg_tmp++) { + if (tc_cmac_update(&state, sg_tmp->data, sg_tmp->len) == TC_CRYPTO_FAIL) { return -EIO; } } diff --git a/wm800/board/src/bt/blehost/nimble/host/mesh/src/proxy.c b/wm800/board/src/bt/blehost/nimble/host/mesh/src/proxy.c index 9e01b5f..982d8a9 100755 --- a/wm800/board/src/bt/blehost/nimble/host/mesh/src/proxy.c +++ b/wm800/board/src/bt/blehost/nimble/host/mesh/src/proxy.c @@ -972,22 +972,22 @@ static int proxy_segment_and_send(uint16_t conn_handle, u8_t type, /* ATT_MTU - OpCode (1 byte) - Handle (2 bytes) */ mtu = ble_att_mtu(conn_handle) - 3; // 3:byte alignment if (mtu > msg->om_len) { - net_buf_simple_push_u8(msg, PDU_HDR(SAR_COMPLETE, type)); + net_buf_simple_push_u8(msg, PDU_HDR((SAR_COMPLETE), (type))); return proxy_send(conn_handle, msg->om_data, msg->om_len); } - net_buf_simple_push_u8(msg, PDU_HDR(SAR_FIRST, type)); + net_buf_simple_push_u8(msg, PDU_HDR((SAR_FIRST), (type))); proxy_send(conn_handle, msg->om_data, mtu); net_buf_simple_pull(msg, mtu); while (msg->om_len) { if (msg->om_len + 1 < mtu) { - net_buf_simple_push_u8(msg, PDU_HDR(SAR_LAST, type)); + net_buf_simple_push_u8(msg, PDU_HDR((SAR_LAST), (type))); proxy_send(conn_handle, msg->om_data, msg->om_len); break; } - net_buf_simple_push_u8(msg, PDU_HDR(SAR_CONT, type)); + net_buf_simple_push_u8(msg, PDU_HDR((SAR_CONT), (type))); proxy_send(conn_handle, msg->om_data, mtu); net_buf_simple_pull(msg, mtu); } diff --git a/wm800/board/src/bt/blehost/nimble/host/mesh/src/shell.c b/wm800/board/src/bt/blehost/nimble/host/mesh/src/shell.c index 295c998..a048cd7 100755 --- a/wm800/board/src/bt/blehost/nimble/host/mesh/src/shell.c +++ b/wm800/board/src/bt/blehost/nimble/host/mesh/src/shell.c @@ -1590,8 +1590,7 @@ static int cmd_mod_pub(int argc, char *argv[]) } struct shell_cmd_help cmd_mod_pub_help = { - NULL, " [cid] [ " \ - " ]", NULL + NULL, " [cid] [ ]", NULL }; static void hb_sub_print(struct bt_mesh_cfg_hb_sub *sub) diff --git a/wm800/board/src/bt/blehost/nimble/host/mesh/src/testing.c b/wm800/board/src/bt/blehost/nimble/host/mesh/src/testing.c index 1f0cc0f..dbb093e 100755 --- a/wm800/board/src/bt/blehost/nimble/host/mesh/src/testing.c +++ b/wm800/board/src/bt/blehost/nimble/host/mesh/src/testing.c @@ -5,10 +5,10 @@ */ #include -#include "mesh/testing.h" #include "mesh/slist.h" #include "mesh/glue.h" #include "mesh/access.h" +#include "mesh/testing.h" #include "net.h" #include "access.h" diff --git a/wm800/board/src/bt/blehost/nimble/host/mesh/src/transport.c b/wm800/board/src/bt/blehost/nimble/host/mesh/src/transport.c index b5723a4..4358fd6 100755 --- a/wm800/board/src/bt/blehost/nimble/host/mesh/src/transport.c +++ b/wm800/board/src/bt/blehost/nimble/host/mesh/src/transport.c @@ -334,7 +334,7 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct os_mbuf *sdu, tx->dst = net_tx->ctx->addr; tx->seg_n = (sdu->om_len - 1) / 12; // 12:byte alignment tx->nack_count = tx->seg_n + 1; - tx->seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_TX, bt_mesh.seq); + tx->seq_auth = (SEQ_AUTH(BT_MESH_NET_IVI_TX, bt_mesh.seq)); tx->sub = net_tx->sub; tx->new_key = net_tx->sub->kr_flag; tx->cb = cb; @@ -736,19 +736,19 @@ static int trans_ack(struct bt_mesh_net_rx *rx, u8_t hdr, u16_t seq_zero; u8_t obo; - if (buf->om_len < 6) { + if (buf->om_len < 6) { // 6:Analyzing conditions BT_ERR("Too short ack message"); return -EINVAL; } seq_zero = net_buf_simple_pull_be16(buf); - obo = seq_zero >> 15; - seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK; + obo = seq_zero >> 15; // 15:byte alignment + seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK; // 2:byte alignment if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && rx->friend_match) { BT_DBG("Ack for LPN 0x%04x of this Friend", rx->ctx.recv_dst); /* Best effort - we don't have enough info for true SeqAuth */ - *seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_RX(rx), seq_zero); + *seq_auth = (SEQ_AUTH(BT_MESH_NET_IVI_RX(rx), seq_zero)); return 0; } @@ -939,9 +939,9 @@ static inline s32_t ack_timeout(struct seg_rx *rx) /* The acknowledgment timer shall be set to a minimum of * 150 + 50 * TTL milliseconds. */ - to = K_MSEC(150 + (50 * ttl)); + to = K_MSEC(150 + (50 * ttl)); // 150:byte, 50:byte alignment /* 100 ms for every not yet received segment */ - to += K_MSEC(((rx->seg_n + 1) - popcount(rx->block)) * 100); + to += K_MSEC(((rx->seg_n + 1) - popcount(rx->block)) * 100); // 100:100ms /* Make sure we don't send more frequently than the duration for * each packet (default is 300ms). */ @@ -1179,7 +1179,7 @@ static int trans_seg(struct os_mbuf *buf, struct bt_mesh_net_rx *net_rx, u8_t seg_o; int err; - if (buf->om_len < 5) { + if (buf->om_len < 5) { // 5:loop condition BT_ERR("Too short segmented message (len %u)", buf->om_len); return -EINVAL; } @@ -1193,10 +1193,10 @@ static int trans_seg(struct os_mbuf *buf, struct bt_mesh_net_rx *net_rx, BT_DBG("ASZMIC %u AKF %u AID 0x%02x", ASZMIC(hdr), AKF(hdr), AID(hdr)); net_buf_simple_pull(buf, 1); seq_zero = net_buf_simple_pull_be16(buf); - seg_o = (seq_zero & 0x03) << 3; - seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK; + seg_o = (seq_zero & 0x03) << 3; // 3:byte alignment + seq_zero = (seq_zero >> 2) & TRANS_SEQ_ZERO_MASK; // 2:byte alignment seg_n = net_buf_simple_pull_u8(buf); - seg_o |= seg_n >> 5; + seg_o |= seg_n >> 5; // 5:byte alignment seg_n &= 0x1f; BT_DBG("SeqZero 0x%04x SegO %u SegN %u", seq_zero, seg_o, seg_n); @@ -1218,10 +1218,10 @@ static int trans_seg(struct os_mbuf *buf, struct bt_mesh_net_rx *net_rx, * Mentioned delta shall be >= 0, if it is not then seq_auth will * be broken and it will be verified by the code below. */ - *seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_RX(net_rx), + *seq_auth = (SEQ_AUTH(BT_MESH_NET_IVI_RX(net_rx), (net_rx->seq - ((((net_rx->seq & BIT_MASK(14)) - seq_zero)) & - BIT_MASK(13)))); + BIT_MASK(13))))); *seg_count = seg_n + 1; /* Look for old RX sessions */ rx = seg_rx_find(net_rx, seq_auth); diff --git a/wm800/board/src/bt/blehost/nimble/host/src/ble_att_svr.c b/wm800/board/src/bt/blehost/nimble/host/src/ble_att_svr.c index bbb75c9..8c5bcdd 100755 --- a/wm800/board/src/bt/blehost/nimble/host/src/ble_att_svr.c +++ b/wm800/board/src/bt/blehost/nimble/host/src/ble_att_svr.c @@ -567,6 +567,7 @@ static int ble_att_svr_tx_rsp(uint16_t conn_handle, int hs_status, struct os_mbu struct ble_l2cap_chan *chan; struct ble_hs_conn *conn; int do_tx; + struct os_mbuf *om_tmp = om; int hs_status_tmp = hs_status; if (hs_status_tmp != 0 && err_status == 0) { @@ -584,11 +585,11 @@ static int ble_att_svr_tx_rsp(uint16_t conn_handle, int hs_status, struct os_mbu hs_status_tmp = rc; } else { if (hs_status_tmp == 0) { - BLE_HS_DBG_ASSERT(om != NULL); - ble_att_inc_tx_stat(om->om_data[0]); - ble_att_truncate_to_mtu(chan, om); - hs_status_tmp = ble_l2cap_tx(conn, chan, om); - om = NULL; + BLE_HS_DBG_ASSERT(om_tmp != NULL); + ble_att_inc_tx_stat(om_tmp->om_data[0]); + ble_att_truncate_to_mtu(chan, om_tmp); + hs_status_tmp = ble_l2cap_tx(conn, chan, om_tmp); + om_tmp = NULL; if (hs_status_tmp != 0) { err_status = BLE_ATT_ERR_UNLIKELY; @@ -602,22 +603,22 @@ static int ble_att_svr_tx_rsp(uint16_t conn_handle, int hs_status, struct os_mbu STATS_INC(ble_att_stats, error_rsp_tx); /* Reuse om for error response. */ - if (om == NULL) { - om = ble_hs_mbuf_l2cap_pkt(); + if (om_tmp == NULL) { + om_tmp = ble_hs_mbuf_l2cap_pkt(); } else { - os_mbuf_adj(om, OS_MBUF_PKTLEN(om)); + os_mbuf_adj(om_tmp, OS_MBUF_PKTLEN(om_tmp)); } - if (om != NULL) { - ble_att_svr_tx_error_rsp(conn_handle, om, att_op, + if (om_tmp != NULL) { + ble_att_svr_tx_error_rsp(conn_handle, om_tmp, att_op, err_handle, err_status); - om = NULL; + om_tmp = NULL; } } } /* Free mbuf if it was not consumed (i.e., if the send failed). */ - os_mbuf_free_chain(om); + os_mbuf_free_chain(om_tmp); return hs_status_tmp; } @@ -2146,7 +2147,6 @@ int ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom) * 5. Invalid handle. * 6. Write not permitted. */ - /* <5> */ if (attr_entry == NULL) { rc = BLE_HS_ENOENT;