diff options
author | Lee Salzman <[email protected]> | 2014-03-08 18:46:39 +0200 |
---|---|---|
committer | Lee Salzman <[email protected]> | 2014-03-08 18:46:39 +0200 |
commit | 73c930881f7acabc9bea99eb698d0824cbe22c3e (patch) | |
tree | edd210e87e2a4eab7bd7ae2112c72732e6b04519 /win32.c | |
parent | 5721b667f2d57d1c8b65ef5575379f6756ec2938 (diff) | |
download | enet-73c930881f7acabc9bea99eb698d0824cbe22c3e.tar.gz enet-73c930881f7acabc9bea99eb698d0824cbe22c3e.zip |
avoid some strncpy usage
Diffstat (limited to 'win32.c')
-rw-r--r-- | win32.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -85,7 +85,13 @@ enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameL char * addr = inet_ntoa (* (struct in_addr *) & address -> host); if (addr == NULL) return -1; - strncpy (name, addr, nameLength); + else + { + size_t addrLen = strlen(addr); + if (addrLen >= nameLength) + return -1; + memcpy (name, addr, addrLen + 1); + } return 0; } @@ -94,14 +100,19 @@ enet_address_get_host (const ENetAddress * address, char * name, size_t nameLeng { struct in_addr in; struct hostent * hostEntry; - + in.s_addr = address -> host; hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET); if (hostEntry == NULL) return enet_address_get_host_ip (address, name, nameLength); - - strncpy (name, hostEntry -> h_name, nameLength); + else + { + size_t hostLen = strlen (hostEntry -> h_name); + if (hostLen >= nameLength) + return -1; + memcpy (name, hostEntry -> h_name, hostLen + 1); + } return 0; } |