野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 21191|回复: 1

stm32f407+lwip 接收大数据包,pbuf->next 会越界问题

[复制链接]
发表于 2021-1-9 09:56:20 | 显示全部楼层 |阅读模式
else if(es->state == ES_CONNECTED)
  {
      u8_t *l;
    struct pbuf *tp;
    u16_t  index = 0;
    /* increment message count */
    message_count++;
    tcp_recved(tpcb, p->tot_len);  
    tp = p;
    while(index < p->tot_len)
    {   
        /* Acknowledge data reception */
        l = (u8_t *)tp->payload;
        l = l + tp->len;   
        *l = '\0';
        //strcat(recev_buf,tp->payload);
        memcpy(&recev_buf[index],tp->payload,tp->len);
        index += tp->len;
        tp = tp->next;
    }     
      
    recev_buf[index] = 0;
#ifdef SERIAL_DEBUG            
    printf("%s",recev_buf);
#endif      
    pbuf_free(p);

    ret_err = ERR_OK;
  }


这个是接收部分的代码,当接收的数据很多的时候,第三块pbuf会指向了乱码,使得程序出错了。这是怎么回事呢,是缓冲区的内存设置的不够大吗?有没有人遇到过这个问题?
回复

使用道具 举报

发表于 2021-1-9 17:05:28 | 显示全部楼层
我遇到过,做法是把上位机发过来的数据调整。下位机多余的数据直接丢掉。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-5-14 06:37 , Processed in 0.027005 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表