svn commit: r324928 - head/lib/libugidfw

Ngie Cooper ngie at FreeBSD.org
Mon Oct 23 16:54:32 UTC 2017


Author: ngie
Date: Mon Oct 23 16:54:30 2017
New Revision: 324928
URL: https://svnweb.freebsd.org/changeset/base/324928

Log:
  Remove dead stores
  
  The return value of various snprintf calls was stored in `len` and not used
  in many functions.
  
  MFC after:	1 week
  Reported by:	clang-scanbuild

Modified:
  head/lib/libugidfw/ugidfw.c

Modified: head/lib/libugidfw/ugidfw.c
==============================================================================
--- head/lib/libugidfw/ugidfw.c	Mon Oct 23 16:50:33 2017	(r324927)
+++ head/lib/libugidfw/ugidfw.c	Mon Oct 23 16:54:30 2017	(r324928)
@@ -512,7 +512,6 @@ bsde_parse_uidrange(char *spec, uid_t *min, uid_t *max
 	uid_t uid1, uid2;
 	char *spec1, *spec2, *endp;
 	unsigned long value;
-	size_t len;
 
 	spec2 = spec;
 	spec1 = strsep(&spec2, ":");
@@ -523,8 +522,7 @@ bsde_parse_uidrange(char *spec, uid_t *min, uid_t *max
 	else {
 		value = strtoul(spec1, &endp, 10);
 		if (*endp != '\0') {
-			len = snprintf(errstr, buflen,
-			    "invalid uid: '%s'", spec1);
+			snprintf(errstr, buflen, "invalid uid: '%s'", spec1);
 			return (-1);
 		}
 		uid1 = value;
@@ -541,8 +539,7 @@ bsde_parse_uidrange(char *spec, uid_t *min, uid_t *max
 	else {
 		value = strtoul(spec2, &endp, 10);
 		if (*endp != '\0') {
-			len = snprintf(errstr, buflen,
-			    "invalid uid: '%s'", spec2);
+			snprintf(errstr, buflen, "invalid uid: '%s'", spec2);
 			return (-1);
 		}
 		uid2 = value;
@@ -561,7 +558,6 @@ bsde_parse_gidrange(char *spec, gid_t *min, gid_t *max
 	gid_t gid1, gid2;
 	char *spec1, *spec2, *endp;
 	unsigned long value;
-	size_t len;
 
 	spec2 = spec;
 	spec1 = strsep(&spec2, ":");
@@ -572,8 +568,7 @@ bsde_parse_gidrange(char *spec, gid_t *min, gid_t *max
 	else {
 		value = strtoul(spec1, &endp, 10);
 		if (*endp != '\0') {
-			len = snprintf(errstr, buflen,
-			    "invalid gid: '%s'", spec1);
+			snprintf(errstr, buflen, "invalid gid: '%s'", spec1);
 			return (-1);
 		}
 		gid1 = value;
@@ -590,8 +585,7 @@ bsde_parse_gidrange(char *spec, gid_t *min, gid_t *max
 	else {
 		value = strtoul(spec2, &endp, 10);
 		if (*endp != '\0') {
-			len = snprintf(errstr, buflen,
-			    "invalid gid: '%s'", spec2);
+			snprintf(errstr, buflen, "invalid gid: '%s'", spec2);
 			return (-1);
 		}
 		gid2 = value;
@@ -613,7 +607,6 @@ bsde_parse_subject(int argc, char *argv[],
 	uid_t uid_min, uid_max;
 	gid_t gid_min, gid_max;
 	int jid = 0;
-	size_t len;
 	long value;
 
 	current = 0;
@@ -630,11 +623,11 @@ bsde_parse_subject(int argc, char *argv[],
 	while (current < argc) {
 		if (strcmp(argv[current], "uid") == 0) {
 			if (current + 2 > argc) {
-				len = snprintf(errstr, buflen, "uid short");
+				snprintf(errstr, buflen, "uid short");
 				return (-1);
 			}
 			if (flags & MBS_UID_DEFINED) {
-				len = snprintf(errstr, buflen, "one uid only");
+				snprintf(errstr, buflen, "one uid only");
 				return (-1);
 			}
 			if (bsde_parse_uidrange(argv[current+1],
@@ -648,11 +641,11 @@ bsde_parse_subject(int argc, char *argv[],
 			current += 2;
 		} else if (strcmp(argv[current], "gid") == 0) {
 			if (current + 2 > argc) {
-				len = snprintf(errstr, buflen, "gid short");
+				snprintf(errstr, buflen, "gid short");
 				return (-1);
 			}
 			if (flags & MBS_GID_DEFINED) {
-				len = snprintf(errstr, buflen, "one gid only");
+				snprintf(errstr, buflen, "one gid only");
 				return (-1);
 			}
 			if (bsde_parse_gidrange(argv[current+1],
@@ -666,17 +659,17 @@ bsde_parse_subject(int argc, char *argv[],
 			current += 2;
 		} else if (strcmp(argv[current], "jailid") == 0) {
 			if (current + 2 > argc) {
-				len = snprintf(errstr, buflen, "prison short");
+				snprintf(errstr, buflen, "prison short");
 				return (-1);
 			}
 			if (flags & MBS_PRISON_DEFINED) {
-				len = snprintf(errstr, buflen, "one jail only");
+				snprintf(errstr, buflen, "one jail only");
 				return (-1);
 			}
 			value = strtol(argv[current+1], &endp, 10);
 			if (*endp != '\0') {
-				len = snprintf(errstr, buflen,
-				    "invalid jid: '%s'", argv[current+1]);
+				snprintf(errstr, buflen, "invalid jid: '%s'",
+				    argv[current+1]);
 				return (-1);
 			}
 			jid = value;
@@ -688,14 +681,13 @@ bsde_parse_subject(int argc, char *argv[],
 			current += 2;
 		} else if (strcmp(argv[current], "!") == 0) {
 			if (nextnot) {
-				len = snprintf(errstr, buflen,
-				    "double negative");
+				snprintf(errstr, buflen, "double negative");
 				return (-1);
 			}
 			nextnot = 1;
 			current += 1;
 		} else {
-			len = snprintf(errstr, buflen, "'%s' not expected",
+			snprintf(errstr, buflen, "'%s' not expected",
 			    argv[current]);
 			return (-1);
 		}
@@ -723,7 +715,6 @@ bsde_parse_subject(int argc, char *argv[],
 static int
 bsde_parse_type(char *spec, int *type, size_t buflen, char *errstr)
 {
-	size_t len;
 	int i;
 
 	*type = 0;
@@ -755,10 +746,10 @@ bsde_parse_type(char *spec, int *type, size_t buflen, 
 			*type |= MBO_ALL_TYPE;
 			break;
 		default:
-			len = snprintf(errstr, buflen, "Unknown type code: %c",
+			snprintf(errstr, buflen, "Unknown type code: %c",
 			    spec[i]);
 			return (-1);
-		} 
+		}
 	}
 
 	return (0);
@@ -767,11 +758,10 @@ bsde_parse_type(char *spec, int *type, size_t buflen, 
 static int
 bsde_parse_fsid(char *spec, struct fsid *fsid, size_t buflen, char *errstr)
 {
-	size_t len;
 	struct statfs buf;
 
 	if (statfs(spec, &buf) < 0) {
-		len = snprintf(errstr, buflen, "Unable to get id for %s: %s",
+		snprintf(errstr, buflen, "Unable to get id for %s: %s",
 		    spec, strerror(errno));
 		return (-1);
 	}
@@ -791,7 +781,6 @@ bsde_parse_object(int argc, char *argv[],
 	uid_t uid_min, uid_max;
 	gid_t gid_min, gid_max;
 	struct fsid fsid;
-	size_t len;
 
 	current = 0;
 	flags = 0;
@@ -808,11 +797,11 @@ bsde_parse_object(int argc, char *argv[],
 	while (current < argc) {
 		if (strcmp(argv[current], "uid") == 0) {
 			if (current + 2 > argc) {
-				len = snprintf(errstr, buflen, "uid short");
+				snprintf(errstr, buflen, "uid short");
 				return (-1);
 			}
 			if (flags & MBO_UID_DEFINED) {
-				len = snprintf(errstr, buflen, "one uid only");
+				snprintf(errstr, buflen, "one uid only");
 				return (-1);
 			}
 			if (bsde_parse_uidrange(argv[current+1],
@@ -826,11 +815,11 @@ bsde_parse_object(int argc, char *argv[],
 			current += 2;
 		} else if (strcmp(argv[current], "gid") == 0) {
 			if (current + 2 > argc) {
-				len = snprintf(errstr, buflen, "gid short");
+				snprintf(errstr, buflen, "gid short");
 				return (-1);
 			}
 			if (flags & MBO_GID_DEFINED) {
-				len = snprintf(errstr, buflen, "one gid only");
+				snprintf(errstr, buflen, "one gid only");
 				return (-1);
 			}
 			if (bsde_parse_gidrange(argv[current+1],
@@ -844,11 +833,11 @@ bsde_parse_object(int argc, char *argv[],
 			current += 2;
 		} else if (strcmp(argv[current], "filesys") == 0) {
 			if (current + 2 > argc) {
-				len = snprintf(errstr, buflen, "filesys short");
+				snprintf(errstr, buflen, "filesys short");
 				return (-1);
 			}
 			if (flags & MBO_FSID_DEFINED) {
-				len = snprintf(errstr, buflen, "one fsid only");
+				snprintf(errstr, buflen, "one fsid only");
 				return (-1);
 			}
 			if (bsde_parse_fsid(argv[current+1], &fsid,
@@ -890,11 +879,11 @@ bsde_parse_object(int argc, char *argv[],
 			current += 1;
 		} else if (strcmp(argv[current], "type") == 0) {
 			if (current + 2 > argc) {
-				len = snprintf(errstr, buflen, "type short");
+				snprintf(errstr, buflen, "type short");
 				return (-1);
 			}
 			if (flags & MBO_TYPE_DEFINED) {
-				len = snprintf(errstr, buflen, "one type only");
+				snprintf(errstr, buflen, "one type only");
 				return (-1);
 			}
 			if (bsde_parse_type(argv[current+1], &type,
@@ -908,14 +897,14 @@ bsde_parse_object(int argc, char *argv[],
 			current += 2;
 		} else if (strcmp(argv[current], "!") == 0) {
 			if (nextnot) {
-				len = snprintf(errstr, buflen,
+				snprintf(errstr, buflen,
 				    "double negative'");
 				return (-1);
 			}
 			nextnot = 1;
 			current += 1;
 		} else {
-			len = snprintf(errstr, buflen, "'%s' not expected",
+			snprintf(errstr, buflen, "'%s' not expected",
 			    argv[current]);
 			return (-1);
 		}
@@ -946,16 +935,15 @@ int
 bsde_parse_mode(int argc, char *argv[], mode_t *mode, size_t buflen,
     char *errstr)
 {
-	size_t len;
 	int i;
 
 	if (argc == 0) {
-		len = snprintf(errstr, buflen, "mode expects mode value");
+		snprintf(errstr, buflen, "mode expects mode value");
 		return (-1);
 	}
 
 	if (argc != 1) {
-		len = snprintf(errstr, buflen, "'%s' unexpected", argv[1]);
+		snprintf(errstr, buflen, "'%s' unexpected", argv[1]);
 		return (-1);
 	}
 
@@ -981,7 +969,7 @@ bsde_parse_mode(int argc, char *argv[], mode_t *mode, 
 			/* ignore */
 			break;
 		default:
-			len = snprintf(errstr, buflen, "Unknown mode letter: %c",
+			snprintf(errstr, buflen, "Unknown mode letter: %c",
 			    argv[0][i]);
 			return (-1);
 		} 
@@ -998,17 +986,16 @@ bsde_parse_rule(int argc, char *argv[], struct mac_bsd
 	int object, object_elements, object_elements_length;
 	int mode, mode_elements, mode_elements_length;
 	int error, i;
-	size_t len;
 
 	bzero(rule, sizeof(*rule));
 
 	if (argc < 1) {
-		len = snprintf(errstr, buflen, "Rule must begin with subject");
+		snprintf(errstr, buflen, "Rule must begin with subject");
 		return (-1);
 	}
 
 	if (strcmp(argv[0], "subject") != 0) {
-		len = snprintf(errstr, buflen, "Rule must begin with subject");
+		snprintf(errstr, buflen, "Rule must begin with subject");
 		return (-1);
 	}
 	subject = 0;
@@ -1022,7 +1009,7 @@ bsde_parse_rule(int argc, char *argv[], struct mac_bsd
 			object = i;
 
 	if (object == -1) {
-		len = snprintf(errstr, buflen, "Rule must contain an object");
+		snprintf(errstr, buflen, "Rule must contain an object");
 		return (-1);
 	}
 
@@ -1033,7 +1020,7 @@ bsde_parse_rule(int argc, char *argv[], struct mac_bsd
 			mode = i;
 
 	if (mode == -1) {
-		len = snprintf(errstr, buflen, "Rule must contain mode");
+		snprintf(errstr, buflen, "Rule must contain mode");
 		return (-1);
 	}
 
@@ -1112,12 +1099,12 @@ bsde_check_version(size_t buflen, char *errstr)
 	len = sizeof(version);
 	error = sysctlbyname(MIB ".rule_version", &version, &len, NULL, 0);
 	if (error) {
-		len = snprintf(errstr, buflen, "version check failed: %s",
+		snprintf(errstr, buflen, "version check failed: %s",
 		    strerror(errno));
 		return (-1);
 	}
 	if (version != MB_VERSION) {
-		len = snprintf(errstr, buflen, "module v%d != library v%d",
+		snprintf(errstr, buflen, "module v%d != library v%d",
 		    version, MB_VERSION);
 		return (-1);
 	}
@@ -1134,11 +1121,11 @@ bsde_get_rule_count(size_t buflen, char *errstr)
 	len = sizeof(rule_count);
 	error = sysctlbyname(MIB ".rule_count", &rule_count, &len, NULL, 0);
 	if (error) {
-		len = snprintf(errstr, buflen, "%s", strerror(errno));
+		snprintf(errstr, buflen, "%s", strerror(errno));
 		return (-1);
 	}
 	if (len != sizeof(rule_count)) {
-		len = snprintf(errstr, buflen, "Data error in %s.rule_count",
+		snprintf(errstr, buflen, "Data error in %s.rule_count",
 		    MIB);
 		return (-1);
 	}
@@ -1156,12 +1143,11 @@ bsde_get_rule_slots(size_t buflen, char *errstr)
 	len = sizeof(rule_slots);
 	error = sysctlbyname(MIB ".rule_slots", &rule_slots, &len, NULL, 0);
 	if (error) {
-		len = snprintf(errstr, buflen, "%s", strerror(errno));
+		snprintf(errstr, buflen, "%s", strerror(errno));
 		return (-1);
 	}
 	if (len != sizeof(rule_slots)) {
-		len = snprintf(errstr, buflen, "Data error in %s.rule_slots",
-		    MIB);
+		snprintf(errstr, buflen, "Data error in %s.rule_slots", MIB);
 		return (-1);
 	}
 
@@ -1187,7 +1173,7 @@ bsde_get_rule(int rulenum, struct mac_bsdextended_rule
 	len = 10;
 	error = bsde_get_mib(MIB ".rules", name, &len);
 	if (error) {
-		len = snprintf(errstr, errlen, "%s: %s", MIB ".rules",
+		snprintf(errstr, errlen, "%s: %s", MIB ".rules",
 		    strerror(errno));
 		return (-1);
 	}
@@ -1199,11 +1185,11 @@ bsde_get_rule(int rulenum, struct mac_bsdextended_rule
 	if (error  == -1 && errno == ENOENT)
 		return (-2);
 	if (error) {
-		len = snprintf(errstr, errlen, "%s.%d: %s", MIB ".rules",
+		snprintf(errstr, errlen, "%s.%d: %s", MIB ".rules",
 		    rulenum, strerror(errno));
 		return (-1);
 	} else if (size != sizeof(*rule)) {
-		len = snprintf(errstr, errlen, "Data error in %s.%d: %s",
+		snprintf(errstr, errlen, "Data error in %s.%d: %s",
 		    MIB ".rules", rulenum, strerror(errno));
 		return (-1);
 	}
@@ -1225,7 +1211,7 @@ bsde_delete_rule(int rulenum, size_t buflen, char *err
 	len = 10;
 	error = bsde_get_mib(MIB ".rules", name, &len);
 	if (error) {
-		len = snprintf(errstr, buflen, "%s: %s", MIB ".rules",
+		snprintf(errstr, buflen, "%s: %s", MIB ".rules",
 		    strerror(errno));
 		return (-1);
 	}
@@ -1235,7 +1221,7 @@ bsde_delete_rule(int rulenum, size_t buflen, char *err
 
 	error = sysctl(name, len, NULL, NULL, &rule, 0);
 	if (error) {
-		len = snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
+		snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
 		    rulenum, strerror(errno));
 		return (-1);
 	}
@@ -1257,7 +1243,7 @@ bsde_set_rule(int rulenum, struct mac_bsdextended_rule
 	len = 10;
 	error = bsde_get_mib(MIB ".rules", name, &len);
 	if (error) {
-		len = snprintf(errstr, buflen, "%s: %s", MIB ".rules",
+		snprintf(errstr, buflen, "%s: %s", MIB ".rules",
 		    strerror(errno));
 		return (-1);
 	}
@@ -1267,7 +1253,7 @@ bsde_set_rule(int rulenum, struct mac_bsdextended_rule
 
 	error = sysctl(name, len, NULL, NULL, rule, sizeof(*rule));
 	if (error) {
-		len = snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
+		snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
 		    rulenum, strerror(errno));
 		return (-1);
 	}
@@ -1290,14 +1276,14 @@ bsde_add_rule(int *rulenum, struct mac_bsdextended_rul
 	len = 10;
 	error = bsde_get_mib(MIB ".rules", name, &len);
 	if (error) {
-		len = snprintf(errstr, buflen, "%s: %s", MIB ".rules",
+		snprintf(errstr, buflen, "%s: %s", MIB ".rules",
 		    strerror(errno));
 		return (-1);
 	}
 
 	rule_slots = bsde_get_rule_slots(BUFSIZ, charstr);
 	if (rule_slots == -1) {
-		len = snprintf(errstr, buflen, "unable to get rule slots: %s",
+		snprintf(errstr, buflen, "unable to get rule slots: %s",
 		    strerror(errno));
 		return (-1);
 	}
@@ -1307,7 +1293,7 @@ bsde_add_rule(int *rulenum, struct mac_bsdextended_rul
 
 	error = sysctl(name, len, NULL, NULL, rule, sizeof(*rule));
 	if (error) {
-		len = snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
+		snprintf(errstr, buflen, "%s.%d: %s", MIB ".rules",
 		    rule_slots, strerror(errno));
 		return (-1);
 	}


More information about the svn-src-all mailing list