buf[2]="test"

int fun(void) {    char buf[2] = "test";     int x  = 1;  }

error C2117: 'buf' : array bounds overflow

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
请帮我解释这段代码:#include "cmd_parse.h" static int bufed_uart_rcv_1B(void *ref, uint8_t *c) { BUFED_UART_T *h = ref; return bufed_uart_rcv(h, c, 1); } CMD_PARSE_T *cmd_ps_1; osThreadId rx_cmp_tst_hd; extern RNG_HandleTypeDef hrng; void uart1_fast_loopback_test(uint32_t fatfs_ok) { uint8_t *tx_buf, *rx_buf; tx_buf= pvPortMalloc(URT_TST_BUF_LEN); if(tx_buf == NULL){ GS_LOGPRT_ERR("tx_buf pvPortMalloc failed.\r\n"); goto err_00; } rx_buf= pvPortMalloc(URT_TST_BUF_LEN); if(rx_buf == NULL){ GS_LOGPRT_ERR("tx_buf pvPortMalloc failed.\r\n"); goto err_01; } FIL *fp = pvPortMalloc(sizeof(*fp)); if(fp==NULL){ GS_LOGPRT_ERR("tx_buf pvPortMalloc failed.\r\n"); goto err_02; } bfdurt_tst_01.rx_buf = rx_buf; bfdurt_tst_01.tx_buf = tx_buf; bfdurt_tst_01.buf_size = URT_TST_BUF_LEN; bfdurt_tst_01.err_cnt = 0; for(uint32_t i = 0; i < URT_TST_BUF_LEN; i++) tx_buf[i] = HAL_RNG_GetRandomNumber(&hrng); osThreadDef(rx_cmp_tst_tsk, uart_rx_cmp, osPriorityBelowNormal, 0, 200); rx_cmp_tst_hd = osThreadCreate(osThread(rx_cmp_tst_tsk), &(bfdurt_tst_ptr)); osDelay(120); uint32_t lp; cmdprs_init(&cmd_ps_1, 256, &RBFD_UART_GET_UART(urt2), bufed_uart_rcv_1B); uint32_t f_num = 0; size_t n; while(1){ GS_Printf("Input test data length\r\n"); cmdprs_read_1line(cmd_ps_1); char ch; int scn = sscanf((void*)cmd_ps_1->buf->data,"%lu%c", &lp, &ch); if(scn == 2){ if(ch == 'M' || ch == 'm') lp <<= 10U; else if(ch == 'G' || ch == 'g') lp <<= 20U; else if(ch == 'K' || ch == 'k') ; else lp >>= 10U; lp /= (URT_TST_BUF_LEN/1024); }else{ GS_Printf("ERROR\r\n"); break; }
07-14

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值