From 13e404d7775615e1399a1de18b6c06ea081b99f5 Mon Sep 17 00:00:00 2001 From: Marius Greuel Date: Tue, 10 Mar 2020 20:54:32 +0200 Subject: [PATCH] Improve MSVC patch in stk500.c --- stk500.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/stk500.c b/stk500.c index 167121d5..eff597e6 100644 --- a/stk500.c +++ b/stk500.c @@ -754,10 +754,16 @@ static int stk500_loadaddr(PROGRAMMER * pgm, AVRMEM * mem, unsigned int addr) return -1; } -static int stk500_paged_write2(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, - unsigned char* buf, unsigned int page_size, + +static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, + unsigned int page_size, unsigned int addr, unsigned int n_bytes) { +#ifdef _MSC_VER + unsigned char* buf = _alloca(page_size + 16); +#else + unsigned char buf[page_size + 16]; +#endif int memtype; int a_div; int block_size; @@ -848,16 +854,6 @@ static int stk500_paged_write2(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, return n_bytes; } -static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, - unsigned int page_size, - unsigned int addr, unsigned int n_bytes) -{ - unsigned char* buf = malloc(page_size + 16); - int result = stk500_paged_write2(pgm, p, m, buf, page_size, addr, n_bytes); - free(buf); - return result; -} - static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)