Fix build with -DENABLE_FTDI_BASED_CABLE=off; fix potential array out-of-bounds access (#616)
* Fix build without FTDI cable Signed-off-by: Qi Zhou <atmgnd@outlook.com> * Fix potential array out‑of‑bounds access Signed-off-by: Qi Zhou <atmgnd@outlook.com> --------- Signed-off-by: Qi Zhou <atmgnd@outlook.com> Co-authored-by: Qi Zhou <qi.zhou@unispc.com>
This commit is contained in:
parent
86ae6ed372
commit
ecebc40004
|
|
@ -249,14 +249,17 @@ int CH347Jtag::_setClkFreq(uint32_t clkHZ)
|
||||||
uint32_t *ptr = _is_largerPack ? speed_clock_larger_pack : speed_clock_standard_pack;
|
uint32_t *ptr = _is_largerPack ? speed_clock_larger_pack : speed_clock_standard_pack;
|
||||||
int size = (_is_largerPack?sizeof(speed_clock_larger_pack):sizeof(speed_clock_standard_pack)) / sizeof(uint32_t);
|
int size = (_is_largerPack?sizeof(speed_clock_larger_pack):sizeof(speed_clock_standard_pack)) / sizeof(uint32_t);
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
if (clkHZ > ptr[i] && clkHZ <= ptr[i+1]){
|
if (clkHZ >= ptr[i] ){
|
||||||
setClk_index = i + 1;
|
setClk_index = i;
|
||||||
}
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (setClk(setClk_index)) {
|
if (setClk(setClk_index)) {
|
||||||
printError("failed to set clock rate");
|
printError("failed to set clock rate");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
_clkHZ = ptr[setClk_index];
|
||||||
char mess[256];
|
char mess[256];
|
||||||
snprintf(mess, 256, "JTAG TCK frequency set to %.3f MHz\n\n", (double)ptr[setClk_index] / MHZ(1));
|
snprintf(mess, 256, "JTAG TCK frequency set to %.3f MHz\n\n", (double)ptr[setClk_index] / MHZ(1));
|
||||||
printInfo(mess);
|
printInfo(mess);
|
||||||
|
|
@ -333,7 +336,7 @@ int CH347Jtag::toggleClk(uint8_t tms, uint8_t tdi, uint32_t len)
|
||||||
ptr = obuf;
|
ptr = obuf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CH347Jtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
|
int CH347Jtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
|
||||||
|
|
@ -381,7 +384,7 @@ int CH347Jtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
|
||||||
}
|
}
|
||||||
unsigned actual_length;
|
unsigned actual_length;
|
||||||
if (bits == 0)
|
if (bits == 0)
|
||||||
return EXIT_SUCCESS;
|
return len;
|
||||||
cmd = (rx) ? CMD_BITS_WR : CMD_BITS_WO;
|
cmd = (rx) ? CMD_BITS_WR : CMD_BITS_WO;
|
||||||
if (get_obuf_length() < (int)(4 + bits * 2)) {
|
if (get_obuf_length() < (int)(4 + bits * 2)) {
|
||||||
flush();
|
flush();
|
||||||
|
|
@ -427,5 +430,5 @@ int CH347Jtag::writeTDI(const uint8_t *tx, uint8_t *rx, uint32_t len, bool end)
|
||||||
*rptr &= ~(0x01 << i);
|
*rptr &= ~(0x01 << i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@
|
||||||
#include "anlogic.hpp"
|
#include "anlogic.hpp"
|
||||||
#include "board.hpp"
|
#include "board.hpp"
|
||||||
#include "cable.hpp"
|
#include "cable.hpp"
|
||||||
|
#ifdef USE_LIBFTDI
|
||||||
#include "colognechip.hpp"
|
#include "colognechip.hpp"
|
||||||
|
#endif
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "cxxopts.hpp"
|
#include "cxxopts.hpp"
|
||||||
#include "device.hpp"
|
#include "device.hpp"
|
||||||
|
|
@ -25,12 +27,16 @@
|
||||||
#include "dfu.hpp"
|
#include "dfu.hpp"
|
||||||
#endif
|
#endif
|
||||||
#include "display.hpp"
|
#include "display.hpp"
|
||||||
|
#ifdef USE_LIBFTDI
|
||||||
#include "efinix.hpp"
|
#include "efinix.hpp"
|
||||||
#include "ftdispi.hpp"
|
#include "ftdispi.hpp"
|
||||||
|
#endif
|
||||||
#include "gowin.hpp"
|
#include "gowin.hpp"
|
||||||
#include "ice40.hpp"
|
|
||||||
#include "lattice.hpp"
|
#include "lattice.hpp"
|
||||||
|
#ifdef USE_LIBFTDI
|
||||||
|
#include "ice40.hpp"
|
||||||
#include "latticeSSPI.hpp"
|
#include "latticeSSPI.hpp"
|
||||||
|
#endif
|
||||||
#ifdef ENABLE_USB_SCAN
|
#ifdef ENABLE_USB_SCAN
|
||||||
#include "libusb_ll.hpp"
|
#include "libusb_ll.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue