1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 19:19:53 +00:00

Replace malloc + memset with calloc.

Fixes an overflow warning from gcc with '-Wstringop-overflow' on
NetBSD-current.
This commit is contained in:
Sunil Nimmagadda 2021-01-21 19:35:57 +05:30
parent 0acf167e84
commit 381128364e

View File

@ -263,12 +263,11 @@ static struct addrinfo *janet_get_addrinfo(Janet *argv, int32_t offset, int sock
#ifndef JANET_WINDOWS #ifndef JANET_WINDOWS
if (janet_keyeq(argv[offset], "unix")) { if (janet_keyeq(argv[offset], "unix")) {
const char *path = janet_getcstring(argv, offset + 1); const char *path = janet_getcstring(argv, offset + 1);
struct sockaddr_un *saddr = malloc(sizeof(struct sockaddr_un)); struct sockaddr_un *saddr = calloc(1, sizeof(struct sockaddr_un));
if (saddr == NULL) { if (saddr == NULL) {
JANET_OUT_OF_MEMORY; JANET_OUT_OF_MEMORY;
} }
saddr->sun_family = AF_UNIX; saddr->sun_family = AF_UNIX;
memset(&saddr->sun_path, 0, 108);
#ifdef JANET_LINUX #ifdef JANET_LINUX
if (path[0] == '@') { if (path[0] == '@') {
saddr->sun_path[0] = '\0'; saddr->sun_path[0] = '\0';