Explorar el Código

libdpkg: Do not fallback to strlen() when using strcspn()

The strcspn() function always returns the requested length, there is no
need to fallback to strlen().
Guillem Jover hace 11 años
padre
commit
93748e328f
Se han modificado 2 ficheros con 2 adiciones y 11 borrados
  1. 0 4
      lib/dpkg/pkg-format.c
  2. 2 7
      lib/dpkg/pkg-show.c

+ 0 - 4
lib/dpkg/pkg-format.c

@@ -294,8 +294,6 @@ virt_source_package(struct varbuf *vb,
 		name = pkg->set->name;
 
 	len = strcspn(name, " ");
-	if (len == 0)
-		len = strlen(name);
 
 	varbuf_add_buf(vb, name, len);
 }
@@ -319,8 +317,6 @@ virt_source_version(struct varbuf *vb,
 		version++;
 
 		len = strcspn(version, ")");
-		if (len == 0)
-			len = strlen(version);
 
 		varbuf_add_buf(vb, version, len);
 	}

+ 2 - 7
lib/dpkg/pkg-show.c

@@ -131,20 +131,15 @@ pkg_name(struct pkginfo *pkg, enum pkg_name_arch_when pnaw)
 }
 
 const char *
-pkg_summary(const struct pkginfo *pkg, const struct pkgbin *pkgbin, int *len_ret)
+pkg_summary(const struct pkginfo *pkg, const struct pkgbin *pkgbin, int *len)
 {
 	const char *pdesc;
-	size_t len;
 
 	pdesc = pkgbin->description;
 	if (!pdesc)
 		pdesc = _("(no description available)");
 
-	len = strcspn(pdesc, "\n");
-	if (len == 0)
-		len = strlen(pdesc);
-
-	*len_ret = len;
+	*len = strcspn(pdesc, "\n");
 
 	return pdesc;
 }