From: Kevin McCarthy Date: Wed, 30 Nov 2016 01:44:37 +0000 (-0800) Subject: Add mutt_array_size macro, change interactive_check_cert() to use it. (see #3899) X-Git-Tag: neomutt-20170225~32^2~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=61fa9ff76be1e22d632b38e57ccd1969ba41b2ee;p=neomutt Add mutt_array_size macro, change interactive_check_cert() to use it. (see #3899) While I have reservations about the construct, it does make the interactive_check_cert() menu->max and part loop less fragile. --- diff --git a/lib.h b/lib.h index 84d33b5e7..ee85cb901 100644 --- a/lib.h +++ b/lib.h @@ -84,6 +84,10 @@ # define MAX(a,b) ((a) < (b) ? (b) : (a)) # define MIN(a,b) ((a) < (b) ? (a) : (b)) +/* Use this with care. If the compiler can't see the array + * definition, it obviously won't produce a correct result. */ +#define mutt_array_size(x) (sizeof (x) / sizeof ((x)[0])) + /* For mutt_format_string() justifications */ /* Making left 0 and center -1 is of course completely nonsensical, but * it retains compatibility for any patches that call mutt_format_string. diff --git a/mutt_ssl.c b/mutt_ssl.c index 9c9c23355..92dc50cb4 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -1017,7 +1017,7 @@ static int interactive_check_cert (X509 *cert, int idx, int len) int done, row, i; FILE *fp; - menu->max = 23; + menu->max = mutt_array_size (part) * 2 + 9; menu->dialog = (char **) safe_calloc (1, menu->max * sizeof (char *)); for (i = 0; i < menu->max; i++) menu->dialog[i] = (char *) safe_calloc (1, SHORT_STRING * sizeof (char)); @@ -1026,7 +1026,7 @@ static int interactive_check_cert (X509 *cert, int idx, int len) strfcpy (menu->dialog[row], _("This certificate belongs to:"), SHORT_STRING); row++; x509_subject = X509_get_subject_name (cert); - for (i = 0; i < 7; i++) + for (i = 0; i < mutt_array_size (part); i++) snprintf (menu->dialog[row++], SHORT_STRING, " %s", x509_get_part (x509_subject, part[i])); @@ -1034,7 +1034,7 @@ static int interactive_check_cert (X509 *cert, int idx, int len) strfcpy (menu->dialog[row], _("This certificate was issued by:"), SHORT_STRING); row++; x509_issuer = X509_get_issuer_name (cert); - for (i = 0; i < 7; i++) + for (i = 0; i < mutt_array_size (part); i++) snprintf (menu->dialog[row++], SHORT_STRING, " %s", x509_get_part (x509_issuer, part[i]));