Skip to content

Commit 5d82816

Browse files
committed
fix segfault
1 parent 7be1c25 commit 5d82816

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

address/inet_aton_ex.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include <stdio.h>
2+
#include <stdlib.h>
23
#include <arpa/inet.h>
34

45
int main()
56
{
67
const char *addr1 = "8.8.8.8";
78
const char *addr2 = "192.168.1.256";
89

9-
struct in_addr *naddr1, *naddr2;
10+
struct in_addr *naddr1 = (struct in_addr*)malloc(sizeof(struct in_addr));
11+
struct in_addr *naddr2 = (struct in_addr*)malloc(sizeof(struct in_addr));
1012

1113
if (inet_aton(addr1, naddr1) == 0) {
1214
printf("inet_aton failed! Please check your input address.\n");

0 commit comments

Comments
 (0)