Replace strlen(_PATH_DEV) with sizeof(_PATH_DEV) - 1.

Suggested by:	kib
Approved by:	kib (mentor)
MFC after:	5 days
This commit is contained in:
Andrey V. Elsukov 2010-10-09 20:20:27 +00:00
parent 9c398cc7e0
commit 21bf062e7e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=213662
11 changed files with 29 additions and 29 deletions

View File

@ -153,8 +153,8 @@ concat_label(struct gctl_req *req)
if (!hardcode) if (!hardcode)
bzero(md.md_provider, sizeof(md.md_provider)); bzero(md.md_provider, sizeof(md.md_provider));
else { else {
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
name += strlen(_PATH_DEV); name += sizeof(_PATH_DEV) - 1;
strlcpy(md.md_provider, name, sizeof(md.md_provider)); strlcpy(md.md_provider, name, sizeof(md.md_provider));
} }
md.md_provsize = g_get_mediasize(name); md.md_provsize = g_get_mediasize(name);

View File

@ -776,8 +776,8 @@ eli_init(struct gctl_req *req)
const char *p = prov; const char *p = prov;
unsigned int i; unsigned int i;
if (strncmp(p, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(p, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
p += strlen(_PATH_DEV); p += sizeof(_PATH_DEV) - 1;
snprintf(backfile, sizeof(backfile), "%s%s.eli", snprintf(backfile, sizeof(backfile), "%s%s.eli",
GELI_BACKUP_DIR, p); GELI_BACKUP_DIR, p);
/* Replace all / with _. */ /* Replace all / with _. */

View File

@ -269,8 +269,8 @@ journal_label(struct gctl_req *req)
if (!hardcode) if (!hardcode)
bzero(md.md_provider, sizeof(md.md_provider)); bzero(md.md_provider, sizeof(md.md_provider));
else { else {
if (strncmp(str, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(str, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
str += strlen(_PATH_DEV); str += sizeof(_PATH_DEV) - 1;
strlcpy(md.md_provider, str, sizeof(md.md_provider)); strlcpy(md.md_provider, str, sizeof(md.md_provider));
} }
journal_metadata_encode(&md, sector); journal_metadata_encode(&md, sector);

View File

@ -247,8 +247,8 @@ mirror_label(struct gctl_req *req)
if (!hardcode) if (!hardcode)
bzero(md.md_provider, sizeof(md.md_provider)); bzero(md.md_provider, sizeof(md.md_provider));
else { else {
if (strncmp(str, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(str, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
str += strlen(_PATH_DEV); str += sizeof(_PATH_DEV) - 1;
strlcpy(md.md_provider, str, sizeof(md.md_provider)); strlcpy(md.md_provider, str, sizeof(md.md_provider));
} }
mirror_metadata_encode(&md, sector); mirror_metadata_encode(&md, sector);

View File

@ -187,8 +187,8 @@ find_geom(struct gclass *classp, const char *name)
{ {
struct ggeom *gp; struct ggeom *gp;
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
name += strlen(_PATH_DEV); name += sizeof(_PATH_DEV) - 1;
LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { LIST_FOREACH(gp, &classp->lg_geom, lg_geom) {
if (strcmp(gp->lg_name, name) == 0) if (strcmp(gp->lg_name, name) == 0)
return (gp); return (gp);

View File

@ -244,8 +244,8 @@ raid3_label(struct gctl_req *req)
if (!hardcode) if (!hardcode)
bzero(md.md_provider, sizeof(md.md_provider)); bzero(md.md_provider, sizeof(md.md_provider));
else { else {
if (strncmp(str, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(str, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
str += strlen(_PATH_DEV); str += sizeof(_PATH_DEV) - 1;
strlcpy(md.md_provider, str, sizeof(md.md_provider)); strlcpy(md.md_provider, str, sizeof(md.md_provider));
} }
if (verify && md.md_no == md.md_all - 1) { if (verify && md.md_no == md.md_all - 1) {

View File

@ -172,8 +172,8 @@ shsec_label(struct gctl_req *req)
if (!hardcode) if (!hardcode)
bzero(md.md_provider, sizeof(md.md_provider)); bzero(md.md_provider, sizeof(md.md_provider));
else { else {
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
name += strlen(_PATH_DEV); name += sizeof(_PATH_DEV) - 1;
strlcpy(md.md_provider, name, sizeof(md.md_provider)); strlcpy(md.md_provider, name, sizeof(md.md_provider));
} }
shsec_metadata_encode(&md, sector); shsec_metadata_encode(&md, sector);

View File

@ -197,8 +197,8 @@ stripe_label(struct gctl_req *req)
if (!hardcode) if (!hardcode)
bzero(md.md_provider, sizeof(md.md_provider)); bzero(md.md_provider, sizeof(md.md_provider));
else { else {
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
name += strlen(_PATH_DEV); name += sizeof(_PATH_DEV) - 1;
strlcpy(md.md_provider, name, sizeof(md.md_provider)); strlcpy(md.md_provider, name, sizeof(md.md_provider));
} }
stripe_metadata_encode(&md, sector); stripe_metadata_encode(&md, sector);

View File

@ -144,7 +144,7 @@ static void
pathgen(const char *name, char *path, size_t size) pathgen(const char *name, char *path, size_t size)
{ {
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) != 0) if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) != 0)
snprintf(path, size, "%s%s", _PATH_DEV, name); snprintf(path, size, "%s%s", _PATH_DEV, name);
else else
strlcpy(path, name, size); strlcpy(path, name, size);
@ -375,7 +375,7 @@ virstor_label(struct gctl_req *req)
fflush(stdout); fflush(stdout);
} }
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
fd = open(name, O_RDWR); fd = open(name, O_RDWR);
else { else {
sprintf(param, "%s%s", _PATH_DEV, name); sprintf(param, "%s%s", _PATH_DEV, name);
@ -453,8 +453,8 @@ virstor_label(struct gctl_req *req)
bzero(md.provider, sizeof(md.provider)); bzero(md.provider, sizeof(md.provider));
else { else {
/* convert "/dev/something" to "something" */ /* convert "/dev/something" to "something" */
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) { if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0) {
strlcpy(md.provider, name + strlen(_PATH_DEV), strlcpy(md.provider, name + sizeof(_PATH_DEV) - 1,
sizeof(md.provider)); sizeof(md.provider));
} else } else
strlcpy(md.provider, name, sizeof(md.provider)); strlcpy(md.provider, name, sizeof(md.provider));
@ -509,7 +509,7 @@ virstor_clear(struct gctl_req *req)
"Not fully done (can't clear metadata)."); "Not fully done (can't clear metadata).");
continue; continue;
} }
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
fd = open(name, O_RDWR); fd = open(name, O_RDWR);
else { else {
sprintf(param, "%s%s", _PATH_DEV, name); sprintf(param, "%s%s", _PATH_DEV, name);

View File

@ -305,8 +305,8 @@ g_part_parm_geom(struct gctl_req *req, const char *name, struct g_geom **v)
gname = gctl_get_asciiparam(req, name); gname = gctl_get_asciiparam(req, name);
if (gname == NULL) if (gname == NULL)
return (ENOATTR); return (ENOATTR);
if (strncmp(gname, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(gname, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
gname += strlen(_PATH_DEV); gname += sizeof(_PATH_DEV) - 1;
LIST_FOREACH(gp, &g_part_class.geom, geom) { LIST_FOREACH(gp, &g_part_class.geom, geom) {
if (!strcmp(gname, gp->name)) if (!strcmp(gname, gp->name))
break; break;
@ -329,8 +329,8 @@ g_part_parm_provider(struct gctl_req *req, const char *name,
pname = gctl_get_asciiparam(req, name); pname = gctl_get_asciiparam(req, name);
if (pname == NULL) if (pname == NULL)
return (ENOATTR); return (ENOATTR);
if (strncmp(pname, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(pname, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
pname += strlen(_PATH_DEV); pname += sizeof(_PATH_DEV) - 1;
pp = g_provider_by_name(pname); pp = g_provider_by_name(pname);
if (pp == NULL) { if (pp == NULL) {
gctl_error(req, "%d %s '%s'", EINVAL, name, pname); gctl_error(req, "%d %s '%s'", EINVAL, name, pname);

View File

@ -316,8 +316,8 @@ virstor_ctl_add(struct gctl_req *req, struct g_class *cp)
g_topology_unlock(); g_topology_unlock();
return; return;
} }
if (strncmp(prov_name, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(prov_name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
prov_name += strlen(_PATH_DEV); prov_name += sizeof(_PATH_DEV) - 1;
pp = g_provider_by_name(prov_name); pp = g_provider_by_name(prov_name);
if (pp == NULL) { if (pp == NULL) {
@ -574,8 +574,8 @@ virstor_ctl_remove(struct gctl_req *req, struct g_class *cp)
gctl_error(req, "Error fetching argument '%s'", param); gctl_error(req, "Error fetching argument '%s'", param);
return; return;
} }
if (strncmp(prov_name, _PATH_DEV, strlen(_PATH_DEV)) == 0) if (strncmp(prov_name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
prov_name += strlen(_PATH_DEV); prov_name += sizeof(_PATH_DEV) - 1;
found = -1; found = -1;
for (j = 0; j < sc->n_components; j++) { for (j = 0; j < sc->n_components; j++) {