diff options
-rw-r--r-- | halfkay.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -89,10 +89,11 @@ static void usbsendcmd(void *data, size_t size, bool firstxfer) static void fmtcmd(void *_dest, const struct flashparams *fp, size_t addr) { + static const size_t MAX_SHIFT = sizeof addr * CHAR_BIT / 8; unsigned char *dest = _dest; addr >>= fp->addrshft; - for (size_t i = 0; i < fp->cmdsz; i++) + for (size_t i = 0; i < fp->cmdsz && i < MAX_SHIFT; i++) dest[i] = (addr >> (i * 8)) & 0xFF; } |