When we know the size we can avoid using strcpy.
{
struct dir_list *dl;
struct stat st;
+ size_t len;
if (stat(path, &st)) {
log_warn("Ignoring %s: %s.", path, strerror(errno));
return 1;
}
- if (!(dl = _zalloc(sizeof(*dl) + strlen(path) + 1))) {
+ len = strlen(path);
+ if (!(dl = _zalloc(sizeof(*dl) + len + 1))) {
log_error("dir_list allocation failed");
return 0;
}
- strcpy(dl->dir, path);
+ memcpy(dl->dir, path, len + 1);
dm_list_add(&_cache.dirs, &dl->list);
return 1;
}
struct labeller_i *li;
size_t len;
- len = sizeof(*li) + strlen(name) + 1;
+ len = strlen(name);
- if (!(li = malloc(len))) {
+ if (!(li = malloc(sizeof(*li) + len + 1))) {
log_error("Couldn't allocate memory for labeller list object.");
return NULL;
}
li->l = l;
- strcpy(li->name, name);
+ memcpy(li->name, name, len + 1);
return li;
}
!buffer_realloc(buf, len + 1))
return 0;
- strcpy(buf->mem + buf->used, string);
+ memcpy(buf->mem + buf->used, string, len + 1);
buf->used += len;
return 1;
}