From 7e3a73558e8d1a410e225a0b102db38891a4990e Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 28 Jan 2023 19:39:34 +0000 Subject: util/nvmutil: don't use malloc() --- util/nvmutil/nvmutil.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 890d2c3f..517cbc79 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -57,8 +57,8 @@ void writeGbeFile(int *fd, const char *filename); #define SIZE_4KB 0x1000 #define SIZE_8KB 0x2000 -uint8_t *buf = NULL; -size_t gbe[2]; +uint8_t buf[SIZE_8KB]; +size_t gbe[2] = {(size_t) buf, ((size_t) buf) + SIZE_4KB}; uint8_t skipread[2] = {0, 0}; int part, gbeFileModified = 0; @@ -80,10 +80,6 @@ main(int argc, char *argv[]) err(errno, "pledge"); #endif - if ((buf = (uint8_t *) malloc(SIZE_8KB)) == NULL) - err(errno, NULL); - gbe[1] = (gbe[0] = (size_t) buf) + SIZE_4KB; - test = 1; little_endian = ((uint8_t *) &test)[0]; @@ -402,6 +398,7 @@ word(int pos16, int partnum) uint8_t *nbuf = (uint8_t *) gbe[partnum]; uint16_t pos8 = pos16 << 1; uint16_t val16 = nbuf[pos8 + 1]; + val16 <<= 8; return val16 |= nbuf[pos8]; } @@ -412,6 +409,7 @@ setWord(int pos16, int partnum, uint16_t val16) uint8_t *nbuf = (uint8_t *) gbe[partnum]; uint8_t val8[2] = {(uint8_t) (val16 & 0xff), (uint8_t) (val16 >> 8)}; uint16_t pos8 = pos16 << 1; + nbuf[pos8] = val8[0]; nbuf[pos8 + 1] = val8[1]; -- cgit v1.2.1