diff
--- a/jdct.c
+++ b/jdct.c
@@ -24,7 +24,10 @@
    cinfo->comps_in_scan = n;
 
    for (i = 0; i < cinfo->num_components; i++)
-       cinfo->cur_comp_info[MIN(i, MAX_COMPS_IN_SCAN - 1)] = NULL; 
+       if (i < MAX_COMPS_IN_SCAN) {
+           cinfo->cur_comp_info[i] = NULL;
+       }
+
    
    /* Initialize the scan parameters.  We'll use the same values for all
      * components, so only need to do this once.

