display_stat(struct writer *w, const char *tag, const char *descr,
long unsigned int cnt)
{
- char buf[20];
+ char buf[20] = {};
tag_start(w, tag, descr);
- memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf), "%lu", cnt );
tag_attr(w, tag, "", buf);
tag_end(w);
enum hmsg_type type,
void *t, struct marshal_info *mi)
{
- struct hmsg_header hdr;
ssize_t len = 0, newlen;
void *buffer = NULL;
}
*output_buffer = new;
}
- memset(&hdr, 0, sizeof(struct hmsg_header));
- hdr.type = type;
- hdr.len = len;
+
+ struct hmsg_header hdr = {
+ .type = type,
+ .len = len
+ };
memcpy(*output_buffer + *output_len, &hdr, sizeof(struct hmsg_header));
if (t)
memcpy(*output_buffer + *output_len + sizeof(struct hmsg_header), buffer, len);
if (t == NULL || t->sock < 0)
goto recv_error;
- to = (struct sockaddr *)malloc(sizeof(struct sockaddr_un));
+ to = (struct sockaddr *)calloc(1, sizeof(struct sockaddr_un));
if (to == NULL)
goto recv_error;
- memset(to, 0, tolen);
if (getsockname(t->sock, to, &tolen) != 0)
goto recv_error;
while (rc < 0) {
static netsnmp_transport *
agent_priv_unix_transport(const char *string, int len, int local)
{
- struct sockaddr_un addr;
+ struct sockaddr_un addr = {
+ .sun_family = AF_UNIX
+ };
netsnmp_transport *t = NULL;
-
+
if (local) {
log_warnx("snmp", "should not have been called for local transport");
return NULL;
}
if (!string)
return NULL;
- if (len > 0 && len < (sizeof(addr.sun_path) - 1)) {
- addr.sun_family = AF_UNIX;
- memset(addr.sun_path, 0, sizeof(addr.sun_path));
- strncpy(addr.sun_path, string, len);
- } else {
+ if (len >= sizeof(addr.sun_path) ||
+ strlcpy(addr.sun_path, string, sizeof(addr.sun_path)) >= sizeof(addr.sun_path))
log_warnx("snmp", "path too long for Unix domain transport");
return NULL;
}
if ((t = (netsnmp_transport *)
- malloc(sizeof(netsnmp_transport))) == NULL)
+ calloc(1, sizeof(netsnmp_transport))) == NULL)
return NULL;
- memset(t, 0, sizeof(netsnmp_transport));
-
t->domain = netsnmp_unix;
t->domain_length =
sizeof(netsnmp_unix) / sizeof(netsnmp_unix[0]);
#endif
length = hardware->h_mtu;
- if ((packet = (u_int8_t*)malloc(length)) == NULL)
+ if ((packet = (u_int8_t*)calloc(1, length)) == NULL)
return ENOMEM;
- memset(packet, 0, length);
pos = packet;
/* Ethernet header */
dmi_get(char *file)
{
int dmi, s;
- char buffer[100];
+ char buffer[100] = {};
log_debug("localchassis", "DMI request for file %s", file);
if ((dmi = priv_open(file)) < 0) {
log_debug("localchassis", "cannot get DMI file %s", file);
return NULL;
}
- memset(buffer, 0, sizeof(buffer));
if ((s = read(dmi, buffer, sizeof(buffer))) == -1) {
log_debug("localchassis", "cannot read DMI file %s", file);
close(dmi);
while (state != 2) {
#endif
length = hardware->h_mtu;
- if ((packet = (u_int8_t*)malloc(length)) == NULL)
+ if ((packet = (u_int8_t*)calloc(1, length)) == NULL)
return ENOMEM;
- memset(packet, 0, length);
pos = packet;
v = 0;
{
#ifdef ENABLE_OLDIES
int j;
- int ifptindices[MAX_PORTS];
+ int ifptindices[MAX_PORTS] = {};
unsigned long args2[4] = {
BRCTL_GET_PORT_LIST,
(unsigned long)ifptindices,
MAX_PORTS,
0
};
- struct ifreq ifr;
+ struct ifreq ifr = {
+ .ifr_data = (char*)&args2
+ };
strncpy(ifr.ifr_name, iface->name, IFNAMSIZ);
- memset(ifptindices, 0, sizeof(ifptindices));
- ifr.ifr_data = (char *)&args2;
if (ioctl(cfg->g_sock, SIOCDEVPRIVATE, &ifr) < 0)
/* This can happen with a 64bit kernel and 32bit
struct interfaces_device_list *interfaces,
struct interfaces_device *iface)
{
- struct vlan_ioctl_args ifv;
- memset(&ifv, 0, sizeof(ifv));
+ struct vlan_ioctl_args ifv = {};
ifv.cmd = GET_VLAN_REALDEV_NAME_CMD;
strlcpy(ifv.device1, iface->name, sizeof(ifv.device1));
if (ioctl(cfg->g_sock, SIOCGIFVLAN, &ifv) >= 0) {
struct interfaces_device_list *interfaces,
struct interfaces_device *master)
{
- struct ifreq ifr;
- struct ifbond ifb;
- memset(&ifr, 0, sizeof(ifr));
- memset(&ifb, 0, sizeof(ifb));
+ struct ifreq ifr = {};
+ struct ifbond ifb = {};
strlcpy(ifr.ifr_name, master->name, sizeof(ifr.ifr_name));
ifr.ifr_data = (char *)&ifb;
if (ioctl(cfg->g_sock, SIOCBONDINFOQUERY, &ifr) >= 0) {
{
struct interfaces_device *iface;
TAILQ_FOREACH(iface, interfaces, next) {
- struct iwreq iwr;
- memset(&iwr, 0, sizeof(struct iwreq));
+ struct iwreq iwr = {};
strlcpy(iwr.ifr_name, iface->name, IFNAMSIZ);
if (ioctl(cfg->g_sock, SIOCGIWNAME, &iwr) >= 0) {
log_debug("interfaces", "%s is wireless",
port = &hardware->h_lport;
chassis = port->p_chassis;
length = hardware->h_mtu;
- if ((packet = (u_int8_t*)malloc(length)) == NULL)
+ if ((packet = (u_int8_t*)calloc(1, length)) == NULL)
return ENOMEM;
- memset(packet, 0, length);
pos = packet;
/* Ethernet header */
static void
asroot_ethtool()
{
- struct ifreq ifr;
- struct ethtool_cmd ethc;
+ struct ifreq ifr = {};
+ struct ethtool_cmd ethc = {};
int len, rc;
char *ifname;
- memset(&ifr, 0, sizeof(ifr));
- memset(ðc, 0, sizeof(ethc));
must_read(remote, &len, sizeof(int));
if ((ifname = (char*)malloc(len + 1)) == NULL)
fatal("privsep", NULL);
chassis = hardware->h_lport.p_chassis;
length = hardware->h_mtu;
- if ((packet = (u_int8_t*)malloc(length)) == NULL)
+ if ((packet = (u_int8_t*)calloc(1, length)) == NULL)
return ENOMEM;
- memset(packet, 0, length);
pos = packet;
/* Ethernet header */
{
struct _lldpctl_atom_config_t *c =
(struct _lldpctl_atom_config_t *)atom;
- struct lldpd_config config;
+ struct lldpd_config config = {};
char *iface_pattern = NULL;
char *description = NULL;
int rc, len;
- memset(&config, 0, sizeof(struct lldpd_config));
len = strlen(value) + 1;
switch (key) {
int rc;
struct _lldpctl_atom_config_t *c =
(struct _lldpctl_atom_config_t *)atom;
- struct lldpd_config config;
- memset(&config, 0, sizeof(struct lldpd_config));
+ struct lldpd_config config = {};
switch (key) {
case lldpctl_k_config_paused:
struct _lldpctl_atom_port_t *p =
(struct _lldpctl_atom_port_t *)atom;
struct lldpd_hardware *hardware = p->hardware;
- struct lldpd_port_set set;
+ struct lldpd_port_set set = {};
int rc;
#ifdef ENABLE_DOT3
return NULL;
}
- memset(&set, 0, sizeof(struct lldpd_port_set));
-
switch (key) {
#ifdef ENABLE_DOT3
case lldpctl_k_port_dot3_power:
return fixed_precision(atom, l, 9, 25, 0, " W", " E");
case lldpctl_k_med_location_altitude:
if (m->location->format != LLDP_MED_LOCFORMAT_COORD) break;
- memset(&l, 0, sizeof(u_int64_t));
+ l = 0;
memcpy(&l, m->location->data + 10, 5);
l = (ntohll(l) & 0x3FFFFFFF000000ULL) >> 24;
return fixed_precision(atom, l, 22, 8, 1, NULL, NULL);