1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

get rid of strncpy as much as possible

This commit is contained in:
Steffen Vogel 2018-04-04 08:53:00 +02:00
parent 47b600efb7
commit f31a7b0ffb
6 changed files with 13 additions and 8 deletions

View file

@ -39,7 +39,7 @@ struct advio {
unsigned char hash[SHA_DIGEST_LENGTH];
char mode[2];
char mode[3];
char *uri;
};

View file

@ -193,7 +193,7 @@ AFILE * afopen(const char *uri, const char *mode)
AFILE *af = alloc(sizeof(AFILE));
strncpy(af->mode, mode, sizeof(af->mode));
snprintf(af->mode, sizeof(af->mode), "%s", mode);
sep = strstr(uri, "://");
if (sep) {

View file

@ -151,7 +151,7 @@ int kernel_get_cmdline_param(const char *param, char *buf, size_t len)
if (strcmp(param, key) == 0) {
if (ret >= 2 && buf)
strncpy(buf, value, len);
snprintf(buf, len, "%s", value);
return 0; /* found */
}

View file

@ -626,7 +626,10 @@ int socket_parse_addr(const char *addr, struct sockaddr *saddr, enum socket_laye
if (layer == SOCKET_LAYER_UNIX) { /* Format: "/path/to/socket" */
sa->sun.sun_family = AF_UNIX;
strncpy(sa->sun.sun_path, addr, sizeof(sa->sun.sun_path));
if (strlen(addr) > sizeof(sa->sun.sun_path)-1)
error("Length of unix socket path is too long!");
memcpy(sa->sun.sun_path, addr, strlen(sa->sun.sun_path)+1);
ret = 0;
}

View file

@ -174,8 +174,8 @@ int zeromq_parse(struct node *n, json_t *cfg)
if (strlen(public_key) != 40)
error("Setting 'curve.public_key' of node %s must be a Z85 encoded CurveZMQ key", node_name(n));
strncpy(z->curve.server.public_key, public_key, 41);
strncpy(z->curve.server.secret_key, secret_key, 41);
memcpy(z->curve.server.public_key, public_key, 41);
memcpy(z->curve.server.secret_key, secret_key, 41);
}
/** @todo We should fix this. Its mostly done. */

View file

@ -201,8 +201,10 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg)
if (ret)
jerror(&err, "Failed to parse global configuration");
if (name)
strncpy(sn->name, name, 128);
if (name) {
sn->name = realloc(sn->name, strlen(name)+1);
sprintf(sn->name, "%s", name);
}
#ifdef WITH_WEB
if (json_web)