diff options
author | Andre Heider <a.heider@gmail.com> | 2021-12-15 12:21:48 +0100 |
---|---|---|
committer | David Bauer <mail@david-bauer.net> | 2022-12-07 12:30:17 +0100 |
commit | 902378dc87a88ad3242a8bc4812f8ee6dbf08a90 (patch) | |
tree | b33b120dc377948d5d1ba24a7ca970fd24e23576 /package | |
parent | 4e2d5f4f9f136d52ba76185df897e14586a2af83 (diff) | |
download | upstream-902378dc87a88ad3242a8bc4812f8ee6dbf08a90.tar.gz upstream-902378dc87a88ad3242a8bc4812f8ee6dbf08a90.tar.bz2 upstream-902378dc87a88ad3242a8bc4812f8ee6dbf08a90.zip |
fritz-tools: fritz_tffs_nand: get rid of struct tffs_sectors
This doesn't help and "[0]" gets in the way of bounds checks.
Signed-off-by: Andre Heider <a.heider@gmail.com>
Diffstat (limited to 'package')
-rw-r--r-- | package/utils/fritz-tools/src/fritz_tffs_nand_read.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/package/utils/fritz-tools/src/fritz_tffs_nand_read.c b/package/utils/fritz-tools/src/fritz_tffs_nand_read.c index 32f3cdf693..29b4a5d2e5 100644 --- a/package/utils/fritz-tools/src/fritz_tffs_nand_read.c +++ b/package/utils/fritz-tools/src/fritz_tffs_nand_read.c @@ -73,21 +73,17 @@ static uint8_t readbuf[TFFS_SECTOR_SIZE]; static uint8_t oobbuf[TFFS_SECTOR_OOB_SIZE]; static uint32_t blocksize; static int mtdfd; -struct tffs_sectors *sectors; - -struct tffs_sectors { - uint32_t num_sectors; - uint8_t sectors[0]; -}; +static uint32_t num_sectors; +static uint8_t *sectors; static inline void sector_mark_bad(int num) { - sectors->sectors[num / 8] &= ~(0x80 >> (num % 8)); + sectors[num / 8] &= ~(0x80 >> (num % 8)); }; static inline uint8_t sector_get_good(int num) { - return sectors->sectors[num / 8] & 0x80 >> (num % 8); + return sectors[num / 8] & 0x80 >> (num % 8); }; struct tffs_entry_segment { @@ -176,7 +172,7 @@ static int find_entry(uint32_t id, struct tffs_entry *entry) off_t pos = 0; uint8_t block_end = 0; - for (uint32_t sector = 0; sector < sectors->num_sectors; sector++, pos += TFFS_SECTOR_SIZE) { + for (uint32_t sector = 0; sector < num_sectors; sector++, pos += TFFS_SECTOR_SIZE) { if (block_end) { if (pos % blocksize == 0) { block_end = 0; @@ -417,13 +413,13 @@ static int scan_mtd(void) blocksize = info.erasesize; - sectors = malloc(sizeof(*sectors) + (info.size / TFFS_SECTOR_SIZE + 7) / 8); + num_sectors = info.size / TFFS_SECTOR_SIZE; + sectors = malloc((num_sectors + 7) / 8); if (sectors == NULL) { fprintf(stderr, "ERROR: memory allocation failed!\n"); exit(EXIT_FAILURE); } - sectors->num_sectors = info.size / TFFS_SECTOR_SIZE; - memset(sectors->sectors, 0xff, (info.size / TFFS_SECTOR_SIZE + 7) / 8); + memset(sectors, 0xff, (num_sectors + 7) / 8); uint32_t sector = 0, valid_blocks = 0; uint8_t block_ok = 0; |