Fix wrong array access in set_ft232h_cbus()
[libftdi] / src / ftdi.c
index 07687e8..95028e5 100644 (file)
 #include "ftdi_version_i.h"
 
 #define ftdi_error_return(code, str) do {  \
-        ftdi->error_str = str;             \
+        if ( ftdi )                        \
+            ftdi->error_str = str;         \
+        else                               \
+            fprintf(stderr, str);          \
         return code;                       \
    } while(0);
 
@@ -2406,9 +2409,9 @@ void set_ft232h_cbus(struct ftdi_eeprom *eeprom, unsigned char * output)
         if (eeprom->cbus_function[2*i+1]> CBUSH_CLK7_5)
             mode_high = CBUSH_TRISTATE;
         else
-            mode_high = eeprom->cbus_function[2*i];
+            mode_high = eeprom->cbus_function[2*i+1];
 
-        output[0x18+i] = mode_high <<4 | mode_low;
+        output[0x18+i] = (mode_high <<4) | mode_low;
     }
 }
 /* Return the bits for the encoded EEPROM Structure of a requested Mode