]> diplodocus.org Git - nmh/commitdiff
Use existing macros min() and max() more.
authorRalph Corderoy <ralph@inputplus.co.uk>
Fri, 12 May 2017 21:42:35 +0000 (22:42 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Fri, 12 May 2017 21:42:35 +0000 (22:42 +0100)
13 files changed:
h/mh.h
sbr/arglist.c
sbr/charstring.c
sbr/escape_addresses.c
sbr/fmt_compile.c
sbr/icalparse.y
sbr/m_convert.c
sbr/m_getfld.c
sbr/mime_type.c
sbr/netsec.c
uip/mhical.c
uip/popsbr.c
uip/scansbr.c

diff --git a/h/mh.h b/h/mh.h
index a72971d..e549b2d 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -20,7 +20,7 @@
  * This macro is for use by scan, for example, so that platforms with
  * a small BUFSIZ can easily allocate larger buffers.
  */
-#define NMH_BUFSIZ  (BUFSIZ>=8192 ? BUFSIZ : 8192)
+#define NMH_BUFSIZ  max(BUFSIZ, 8192)
 
 #ifndef FALSE
 #define FALSE false
index 328d9e9..cd88b86 100644 (file)
@@ -199,8 +199,8 @@ argsplit_insert(struct msgs_array *msgs, char *command, char **program)
      */
 
     if (msgs->size + argp >= msgs->max) {
-       msgs->max += MAXMSGS > argp ? MAXMSGS : argp;
-       msgs->msgs = mh_xrealloc(msgs->msgs, msgs->max * sizeof(*msgs->msgs));
+        msgs->max += max(MAXMSGS, argp);
+        msgs->msgs = mh_xrealloc(msgs->msgs, msgs->max * sizeof(*msgs->msgs));
     }
 
     for (i = msgs->size - 1; i >= 0; i--)
index b9b94bd..589b000 100644 (file)
@@ -180,8 +180,8 @@ charstring_last_char_len (const charstring_t s) {
         len = mbtowc (&wide_char, sp, (size_t) MB_CUR_MAX < remaining
                                           ? (size_t) MB_CUR_MAX
                                           : remaining);
-        sp += len > 0 ? len : 1;
-        remaining -= len > 0 ? len : 1;
+        sp += max(len, 1);
+        remaining -= max(len, 1);
     }
 #else  /* ! MULTIBYTE_SUPPORT */
     if (charstring_bytes (s) > 0) { len = 1; }
index a484a11..11a4faa 100644 (file)
@@ -5,7 +5,7 @@
  * complete copyright information.
  */
 
-#include <h/nmh.h>
+#include <h/mh.h>
 #include <h/utils.h>
 
 static void
@@ -76,7 +76,7 @@ escape_component (char *name, size_t namesize, char *chars_to_escape) {
         if (strcmp (tmp, "\"")) {
             size_t len = destp - tmp;
             assert ((ssize_t) strlen(tmp) + 1 == destp - tmp);
-            strncpy (name, tmp, len <= namesize  ?  len  :  namesize);
+            strncpy (name, tmp, min(len, namesize));
         } else {
             /* Handle just " as special case here instead of above. */
             strncpy (name, "\"\\\"\"", namesize);
index f4c8d5d..33f34ef 100644 (file)
@@ -365,7 +365,7 @@ compile_error(char *str, char *cp)
     int i, errpos, errctx;
 
     errpos = cp - format_string;
-    errctx = errpos > 20 ? 20 : errpos;
+    errctx = min(errpos, 20);
     usr_fstring[errpos] = '\0';
 
     for (i = errpos-errctx; i < errpos; i++) {
index 7730726..ac0bc50 100644 (file)
@@ -196,7 +196,7 @@ append (contentline *cline, const char *src, const size_t src_len) {
 
         while (len >= cline->input_line_size) {
             cline->input_line_size = cline->input_line_size == 0
-                ?  (BUFSIZ>=8192 ? BUFSIZ : 8192)
+                ?  max(BUFSIZ, 8192)
                 :  2 * cline->input_line_size;
             cline->input_line =
                 mh_xrealloc (cline->input_line, cline->input_line_size);
index e406268..566b02a 100644 (file)
@@ -202,8 +202,8 @@ single:
             * limits simply reallocate the folder so it's within range.
             */
            if (first < mp->lowoff || first > mp->hghoff)
-               mp = folder_realloc(mp, first < mp->lowoff ? first : mp->lowoff,
-                                   first > mp->hghoff ? first : mp->hghoff);
+                mp = folder_realloc(mp, min(first, mp->lowoff),
+                                    max(first, mp->hghoff));
 
            set_select_empty (mp, first);
        } else {
index 8d78488..0f06803 100644 (file)
@@ -664,7 +664,7 @@ m_getfld (m_getfld_state_t *gstate, char name[NAMESZ], char *buf, int *bufsz,
            max = *bufsz-1;
            /* Back up and store the current position. */
            bp = --s->readpos;
-           c = s->end - s->readpos < max  ?  s->end - s->readpos  :  max;
+            c = min(s->end - s->readpos, max);
            if (s->msg_style != MS_DEFAULT && c > 1) {
                /*
                 * packed maildrop - only take up to the (possible)
index 395c10c..bcc1c39 100644 (file)
@@ -131,7 +131,7 @@ get_file_info(const char *proc, const char *file_name) {
         FILE *fp;
 
         if ((fp = popen(cmd, "r")) != NULL) {
-            char buf[BUFSIZ >= 2048  ?  BUFSIZ  : 2048];
+            char buf[max(BUFSIZ, 2048)];
 
             buf[0] = '\0';
             if (fgets(buf, sizeof buf, fp)) {
index 8a03cad..a64743a 100644 (file)
@@ -391,7 +391,7 @@ netsec_read(netsec_context *nsc, void *buffer, size_t size, char **errstr)
      * assume here that this has something in it.
      */
 
-    retlen = size > nsc->ns_inbuflen ? nsc->ns_inbuflen : size;
+    retlen = min(size, nsc->ns_inbuflen);
 
     memcpy(buffer, nsc->ns_inptr, retlen);
 
index 594a452..67ba90d 100644 (file)
@@ -809,7 +809,7 @@ fold (char *line, int uses_cr) {
 #endif
 
         charstring_push_back_chars (folded_line, cp, char_len, 1);
-        remaining -= char_len > 0 ? char_len : 1;
+        remaining -= max(char_len, 1);
 
         /* remaining must be > 0 to pass the loop condition above, so
            if it's not > 1, it is == 1. */
@@ -824,7 +824,7 @@ fold (char *line, int uses_cr) {
             }
         }
 
-        cp += char_len > 0 ? char_len : 1;
+        cp += max(char_len, 1);
     }
 
     free (line);
index a022957..0d655b8 100644 (file)
@@ -734,7 +734,7 @@ pop_getline (char *s, int n, netsec_context *ns)
      * someday.
      */
 
-    destlen = len < ((size_t) (n - 1)) ? len : (size_t) (n - 1);
+    destlen = min(len, (size_t)(n - 1));
 
     memcpy(s, p, destlen);
     s[destlen] = '\0';
index 715357b..7023502 100644 (file)
@@ -59,7 +59,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
            width = INT_MAX;
        }
        dat[3] = slwidth = width;
-       *scanl = charstring_create (width < NMH_BUFSIZ ? width : NMH_BUFSIZ);
+        *scanl = charstring_create (min(width, NMH_BUFSIZ));
        if (outnum)
            umask(~m_gmprot());