The following commit has been merged in the master branch:
commit 38e2d2d0460b9101125e08c0e9d10deb12908907
Author: Guillem Jover <[EMAIL PROTECTED]>
Date:   Thu Jul 10 09:28:32 2008 +0300

    Use new min and max macros instead of hardcoded tests

diff --git a/ChangeLog b/ChangeLog
index 5eeb626..a24237d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-07-10 Guillem Jover  <[EMAIL PROTECTED]>
+
+       * 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  <[EMAIL PROTECTED]>,
             Timothy G Abbott  <[EMAIL PROTECTED]>
 
diff --git a/lib/dpkg-priv.h b/lib/dpkg-priv.h
index 8638e6d..412b2bd 100644
--- a/lib/dpkg-priv.h
+++ b/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);
diff --git a/lib/fields.c b/lib/fields.c
index 9fc8197..8c181e6 100644
--- a/lib/fields.c
+++ b/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,
diff --git a/lib/tarfn.c b/lib/tarfn.c
index f0ed1a5..9700390 100644
--- a/lib/tarfn.c
+++ b/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;
 
diff --git a/src/configure.c b/src/configure.c
index 0924020..b46e850 100644
--- a/src/configure.c
+++ b/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;
                        }
diff --git a/src/enquiry.c b/src/enquiry.c
index ff385bf..fffe4e9 100644
--- a/src/enquiry.c
+++ b/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;
 }
 
diff --git a/src/main.c b/src/main.c
index 2790180..99ac6c6 100644
--- a/src/main.c
+++ b/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;
diff --git a/src/query.c b/src/query.c
index e6151ab..4259319 100644
--- a/src/query.c
+++ b/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;
 }
 

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to