Skip to content

Commit 8d11b9b

Browse files
authored
Merge pull request #3674 from DavidLin1577/patch-9
[lwip]Fixed a memset bug in ethernetif.c
2 parents b92c265 + 822df76 commit 8d11b9b

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

components/net/lwip-1.4.1/src/netif/ethernetif.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,16 +443,15 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
443443
#if LWIP_NETIF_HOSTNAME
444444
#define LWIP_HOSTNAME_LEN 16
445445
char *hostname = RT_NULL;
446-
netif = (struct netif*) rt_malloc (sizeof(struct netif) + LWIP_HOSTNAME_LEN);
446+
netif = (struct netif*) rt_calloc (1, sizeof(struct netif) + LWIP_HOSTNAME_LEN);
447447
#else
448-
netif = (struct netif*) rt_malloc (sizeof(struct netif));
448+
netif = (struct netif*) rt_calloc (1, sizeof(struct netif));
449449
#endif
450450
if (netif == RT_NULL)
451451
{
452452
rt_kprintf("malloc netif failed\n");
453453
return -RT_ERROR;
454454
}
455-
rt_memset(netif, 0, sizeof(struct netif));
456455

457456
/* set netif */
458457
dev->netif = netif;

components/net/lwip-2.0.2/src/netif/ethernetif.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,16 +494,15 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
494494
#if LWIP_NETIF_HOSTNAME
495495
#define LWIP_HOSTNAME_LEN 16
496496
char *hostname = RT_NULL;
497-
netif = (struct netif*) rt_malloc (sizeof(struct netif) + LWIP_HOSTNAME_LEN);
497+
netif = (struct netif*) rt_calloc (1, sizeof(struct netif) + LWIP_HOSTNAME_LEN);
498498
#else
499-
netif = (struct netif*) rt_malloc (sizeof(struct netif));
499+
netif = (struct netif*) rt_calloc (1, sizeof(struct netif));
500500
#endif
501501
if (netif == RT_NULL)
502502
{
503503
rt_kprintf("malloc netif failed\n");
504504
return -RT_ERROR;
505505
}
506-
rt_memset(netif, 0, sizeof(struct netif));
507506

508507
/* set netif */
509508
dev->netif = netif;

components/net/lwip-2.1.0/src/netif/ethernetif.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,15 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
490490
#if LWIP_NETIF_HOSTNAME
491491
#define LWIP_HOSTNAME_LEN 16
492492
char *hostname = RT_NULL;
493-
netif = (struct netif*) rt_malloc (sizeof(struct netif) + LWIP_HOSTNAME_LEN);
493+
netif = (struct netif*) rt_calloc (1, sizeof(struct netif) + LWIP_HOSTNAME_LEN);
494494
#else
495-
netif = (struct netif*) rt_malloc (sizeof(struct netif));
495+
netif = (struct netif*) rt_calloc (1, sizeof(struct netif));
496496
#endif
497497
if (netif == RT_NULL)
498498
{
499499
rt_kprintf("malloc netif failed\n");
500500
return -RT_ERROR;
501501
}
502-
rt_memset(netif, 0, sizeof(struct netif));
503502

504503
/* set netif */
505504
dev->netif = netif;

0 commit comments

Comments
 (0)