From: Guillem Jover Date: Thu, 10 Jul 2008 06:28:32 +0000 (+0300) Subject: Use new min and max macros instead of hardcoded tests X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38e2d2d0460b9101125e08c0e9d10deb12908907;p=dpkg Use new min and max macros instead of hardcoded tests --- diff --git a/ChangeLog b/ChangeLog index 5eeb6264..a24237df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-07-10 Guillem Jover + + * lib/dpkg-priv.h (min, max): New macros. + * lib/tarfn.c: Include . + * 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 , Timothy G Abbott diff --git a/lib/dpkg-priv.h b/lib/dpkg-priv.h index 8638e6db..412b2bd8 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 9fc81970..8c181e60 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 f0ed1a56..97003903 100644 --- a/lib/tarfn.c +++ b/lib/tarfn.c @@ -15,6 +15,7 @@ #include #include #include +#include #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 09240209..b46e8503 100644 --- a/src/configure.c +++ b/src/configure.c @@ -41,6 +41,7 @@ #include #include +#include #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 ff385bf8..fffe4e9b 100644 --- a/src/enquiry.c +++ b/src/enquiry.c @@ -36,6 +36,7 @@ #include #include +#include #include #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 27901800..99ac6c62 100644 --- a/src/main.c +++ b/src/main.c @@ -36,6 +36,7 @@ #include #include +#include #include #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 e6151ab5..42593192 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; }