From e74528efdcd594d9f40bc8d39ce6a33f45bde615 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Fri, 8 Nov 2013 18:07:20 +0100 Subject: [PATCH] Use new instead of malloc when possible --- kernel/src/disks.cpp | 6 ++---- kernel/src/fat32.cpp | 12 ++++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/kernel/src/disks.cpp b/kernel/src/disks.cpp index 5aaa1ea5..f8c942ce 100644 --- a/kernel/src/disks.cpp +++ b/kernel/src/disks.cpp @@ -121,15 +121,13 @@ bool disks::read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t co } unique_heap_array disks::partitions(const disk_descriptor& disk){ - unique_ptr> buffer(k_malloc(512)); + unique_ptr boot_record(new boot_record_t()); - if(!read_sectors(disk, 0, 1, buffer.get())){ + if(!read_sectors(disk, 0, 1, boot_record.get())){ k_print_line("Read Boot Record failed"); return {}; } else { - auto* boot_record = reinterpret_cast(buffer.get()); - if(boot_record->signature != 0xAA55){ k_print_line("Invalid boot record signature"); diff --git a/kernel/src/fat32.cpp b/kernel/src/fat32.cpp index 20a1afde..7c5bd033 100644 --- a/kernel/src/fat32.cpp +++ b/kernel/src/fat32.cpp @@ -54,25 +54,21 @@ struct fat_is_t { } //end of anonymous namespace void fat32::ls(const disks::disk_descriptor& disk, const disks::partition_descriptor& partition){ - unique_ptr> fat_bs_buffer(k_malloc(512)); + unique_ptr fat_bs(new fat_bs_t()); - if(!read_sectors(disk, partition.start, 1, fat_bs_buffer.get())){ + if(!read_sectors(disk, partition.start, 1, fat_bs.get())){ //TODO } else { - auto* fat_bs = reinterpret_cast(fat_bs_buffer.get()); - //fat_bs->signature should be 0xAA55 //fat_bs->file_system_type should be FAT32 auto fs_information_sector = partition.start + static_cast(fat_bs->fs_information_sector); - unique_ptr> fat_is_buffer(k_malloc(512)); + unique_ptr fat_is(new fat_is_t()); - if(!read_sectors(disk, fs_information_sector, 1, fat_is_buffer.get())){ + if(!read_sectors(disk, fs_information_sector, 1, fat_is.get())){ //TODO } else { - auto* fat_is = reinterpret_cast(fat_is_buffer.get()); - //fat_is->signature_start should be 0x52 0x52 0x61 0x41 //fat_is->signature_middle should be 0x72 0x72 0x41 0x61 //fat_is->signature_end should be 0x00 0x00 0x55 0xAA