From d4f08abec3780be115adbd81008ae0a759c41caa Mon Sep 17 00:00:00 2001 From: DidierA <1620015+DidierA@users.noreply.github.com> Date: Wed, 23 Nov 2022 10:47:55 +0100 Subject: [PATCH] Change calloc() so it passes Widnows build test Code compiles under linux (not tested yet, I have no proxmark available right now) Previous commit fails windows build test with: src/cmdhfmfu.c: In function 'CmdHF14AMfuESave': src/cmdhfmfu.c:4220:19: error: array subscript 'mfu_dump_t[0]' is partly outside array bounds of 'mfu_dump_t[0]' [-Werror=array-bounds] 4220 | end = dump->pages ; | ^~ In function 'GetMfuDumpFromEMul', inlined from 'CmdHF14AMfuESave' at src/cmdhfmfu.c:4202:15: src/cmdhfmfu.c:4105:21: note: object of size 1076 allocated by 'calloc' 4105 | uint8_t *dump = calloc(MFU_MAX_BYTES + MFU_DUMP_PREFIX_LENGTH, sizeof(uint8_t)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- client/src/cmdhfmfu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 138cae25a..c3701a76d 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -4102,20 +4102,20 @@ int CmdHF14MfuNDEFRead(const char *Cmd) { // utility function. Retrieves emulator memory static int GetMfuDumpFromEMul(mfu_dump_t **buf) { - uint8_t *dump = calloc(MFU_MAX_BYTES + MFU_DUMP_PREFIX_LENGTH, sizeof(uint8_t)); + mfu_dump_t *dump = calloc(1, sizeof(mfu_dump_t)); if (dump == NULL) { PrintAndLogEx(WARNING, "Fail, cannot allocate memory"); return PM3_EMALLOC; } PrintAndLogEx(INFO, "downloading from emulator memory"); - if (!GetFromDevice(BIG_BUF_EML, dump, sizeof(mfu_dump_t), 0, NULL, 0, NULL, 2500, false)) { + if (!GetFromDevice(BIG_BUF_EML, (uint8_t *)dump, MFU_MAX_BYTES + MFU_DUMP_PREFIX_LENGTH, 0, NULL, 0, NULL, 2500, false)) { PrintAndLogEx(WARNING, "Fail, transfer from device time-out"); free(dump); return PM3_ETIMEOUT; } - *buf = (mfu_dump_t *)dump ; + *buf = dump ; return PM3_SUCCESS ; }