Forráskód Böngészése

Use new min and max macros instead of hardcoded tests

Guillem Jover 18 éve
szülő
commit
38e2d2d046
8 módosított fájl, 32 hozzáadás és 7 törlés
  1. 14 0
      ChangeLog
  2. 8 0
      lib/dpkg-priv.h
  3. 1 1
      lib/fields.c
  4. 2 2
      lib/tarfn.c
  5. 2 1
      src/configure.c
  6. 2 1
      src/enquiry.c
  7. 2 1
      src/main.c
  8. 1 1
      src/query.c

+ 14 - 0
ChangeLog

@@ -1,3 +1,17 @@
+2008-07-10 Guillem Jover  <guillem@debian.org>
+
+	* lib/dpkg-priv.h (min, max): New macros.
+	* lib/tarfn.c: Include <dpkg-priv.h>.
+	* src/configure.c: Likewise.
+	* src/enquiry.c: Likewise.
+
+	* src/configure.c (conffderef): Use max instead of hardcoded test.
+	* lib/tarfn.c (TarExtractor): Use min instead of hardcoded test.
+	* lib/fields.c (conffvalue_lastword): Likewise.
+	* src/enquiry.c (limiteddescription): Likewise.
+	* src/main.c (setforce): Likewise.
+	* src/query.c (limiteddescription): Likewise.
+
 2008-07-10  Guillem Jover  <guillem@debian.org>,
             Timothy G Abbott  <tabbott@mega-man.mit.edu>
 

+ 8 - 0
lib/dpkg-priv.h

@@ -34,6 +34,14 @@ extern "C" {
 #define sizeof_array(a) (sizeof(a) / sizeof((a)[0]))
 #endif
 
+#ifndef min
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef max
+#define max(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
 /* String handling. */
 
 char *str_escape_fmt(char *dest, const char *src);

+ 1 - 1
lib/fields.c

@@ -246,7 +246,7 @@ static void conffvalue_lastword(const char *value, const char *from,
 malformed:
   parse_error(filename, lno, pigp,
               _("value for `conffiles' has malformatted line `%.*s'"),
-              (int)(endent - value > 250 ? 250 : endent - value), value);
+              (int)min(endent - value, 250), value);
 }
 
 void f_conffiles(struct pkginfo *pigp, struct pkginfoperfile *pifp,

+ 2 - 2
lib/tarfn.c

@@ -15,6 +15,7 @@
 #include <errno.h>
 #include <tarfn.h>
 #include <dpkg.h>
+#include <dpkg-priv.h>
 
 #include "strnlen.h"
 
@@ -245,8 +246,7 @@ TarExtractor(
                      }
                      break;
 		   }
-
-                   copysize = long_read > 512 ? 512 : long_read;
+				copysize = min(long_read, 512);
                    memcpy (bp, buffer, copysize);
                    bp += copysize;
 

+ 2 - 1
src/configure.c

@@ -41,6 +41,7 @@
 
 #include <dpkg.h>
 #include <dpkg-db.h>
+#include <dpkg-priv.h>
 
 #include "filesdb.h"
 #include "main.h"
@@ -380,7 +381,7 @@ int conffderef(struct pkginfo *pkg, struct varbuf *result, const char *in) {
 					return -1;
 				}
 				debug(dbg_conffdetail,"conffderef readlink gave %d, `%.*s'",
-						r, r>0 ? r : 0, linkreadbuf);
+						r, max(r, 0), linkreadbuf);
 				if (r < linkreadbufsize-1) break;
 				need= r<<2;
 			}

+ 2 - 1
src/enquiry.c

@@ -36,6 +36,7 @@
 
 #include <dpkg.h>
 #include <dpkg-db.h>
+#include <dpkg-priv.h>
 #include <myopt.h>
 
 #include "filesdb.h"
@@ -56,7 +57,7 @@ static void limiteddescription(struct pkginfo *pkg, int maxl,
   if (!pdesc) pdesc= _("(no description available)");
   p= strchr(pdesc,'\n');
   if (!p) p= pdesc+strlen(pdesc);
-  l= (p - pdesc > maxl) ? maxl : (int)(p - pdesc);
+  l = min(p - pdesc, maxl);
   *pdesc_r=pdesc; *l_r=l;
 }
 

+ 2 - 1
src/main.c

@@ -36,6 +36,7 @@
 
 #include <dpkg.h>
 #include <dpkg-db.h>
+#include <dpkg-priv.h>
 #include <myopt.h>
 
 #include "main.h"
@@ -361,7 +362,7 @@ static void setforce(const struct cmdinfo *cip, const char *value) {
 	  if (fip->opt)
 	    *fip->opt= cip->arg;
       } else
-	badusage(_("unknown force/refuse option `%.*s'"), l<250 ? (int)l : 250, value);
+	badusage(_("unknown force/refuse option `%.*s'"), min(l, 250), value);
     } else {
       if (fip->opt)
 	*fip->opt= cip->arg;

+ 1 - 1
src/query.c

@@ -62,7 +62,7 @@ static void limiteddescription(struct pkginfo *pkg, int maxl,
   if (!pdesc) pdesc= _("(no description available)");
   p= strchr(pdesc,'\n');
   if (!p) p= pdesc+strlen(pdesc);
-  l= (p - pdesc > maxl) ? maxl : (int)(p - pdesc);
+  l = min(p - pdesc, maxl);
   *pdesc_r=pdesc; *l_r=l;
 }