Use calloc().
MFC after: 2 weeks
This commit is contained in:
parent
b9919ec960
commit
55d26365b1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=351205
@ -54,10 +54,10 @@ static int _readfat(int, struct bootblock *, u_int, u_char **);
|
||||
* 31...... ........ ........ .......0
|
||||
* rrrr1111 11111111 11111111 mmmmmmmm FAT32 entry 0
|
||||
* rrrrsh11 11111111 11111111 11111xxx FAT32 entry 1
|
||||
*
|
||||
*
|
||||
* 11111111 mmmmmmmm FAT16 entry 0
|
||||
* sh111111 11111xxx FAT16 entry 1
|
||||
*
|
||||
*
|
||||
* r = reserved
|
||||
* m = BPB media ID byte
|
||||
* s = clean flag (1 = dismounted; 0 = still mounted)
|
||||
@ -166,11 +166,11 @@ static int
|
||||
_readfat(int fs, struct bootblock *boot, u_int no, u_char **buffer)
|
||||
{
|
||||
off_t off;
|
||||
size_t len;
|
||||
|
||||
*buffer = malloc(len = boot->FATsecs * boot->bpbBytesPerSec);
|
||||
*buffer = calloc(boot->FATsecs, boot->bpbBytesPerSec);
|
||||
if (*buffer == NULL) {
|
||||
perr("No space for FAT sectors (%zu)", len);
|
||||
perr("No space for FAT sectors (%zu)",
|
||||
(size_t)boot->FATsecs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -205,20 +205,19 @@ readfat(int fs, struct bootblock *boot, u_int no, struct fatEntry **fp)
|
||||
u_char *buffer, *p;
|
||||
cl_t cl;
|
||||
int ret = FSOK;
|
||||
size_t len;
|
||||
|
||||
boot->NumFree = boot->NumBad = 0;
|
||||
|
||||
if (!_readfat(fs, boot, no, &buffer))
|
||||
return FSFATAL;
|
||||
|
||||
fat = malloc(len = boot->NumClusters * sizeof(struct fatEntry));
|
||||
fat = calloc(boot->NumClusters, sizeof(struct fatEntry));
|
||||
if (fat == NULL) {
|
||||
perr("No space for FAT clusters (%zu)", len);
|
||||
perr("No space for FAT clusters (%zu)",
|
||||
(size_t)boot->NumClusters);
|
||||
free(buffer);
|
||||
return FSFATAL;
|
||||
}
|
||||
(void)memset(fat, 0, len);
|
||||
|
||||
if (buffer[0] != boot->bpbMedia
|
||||
|| buffer[1] != 0xff || buffer[2] != 0xff
|
||||
@ -566,12 +565,13 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
|
||||
off_t off;
|
||||
int ret = FSOK;
|
||||
|
||||
buffer = malloc(fatsz = boot->FATsecs * boot->bpbBytesPerSec);
|
||||
fatsz = boot->FATsecs * boot->bpbBytesPerSec;
|
||||
buffer = calloc(boot->FATsecs, boot->bpbBytesPerSec);
|
||||
if (buffer == NULL) {
|
||||
perr("No space for FAT sectors (%zu)", fatsz);
|
||||
perr("No space for FAT sectors (%zu)",
|
||||
(size_t)boot->FATsecs);
|
||||
return FSFATAL;
|
||||
}
|
||||
memset(buffer, 0, fatsz);
|
||||
boot->NumFree = 0;
|
||||
p = buffer;
|
||||
if (correct_fat) {
|
||||
|
Loading…
Reference in New Issue
Block a user