Skip to content

Commit c3741ba

Browse files
committed
diskbuilder: Initialize FAT entries properly
1 parent b962780 commit c3741ba

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

diskimagebuild/fat_internal.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ static const uint8_t LAST_LONG_ENTRY = 0x40;
3737
struct cl_dir
3838
{
3939
uint8_t shortname[11];
40-
uint8_t attrib;
40+
uint8_t attrib = 0;
4141
uint8_t pad1[8];
42-
uint16_t cluster_hi;
43-
uint32_t modified;
44-
uint16_t cluster_lo;
45-
uint32_t filesize;
42+
uint16_t cluster_hi = 0;
43+
uint32_t modified = 0;
44+
uint16_t cluster_lo = 0;
45+
uint32_t filesize = 0;
4646

4747
} __attribute__((packed));
4848

diskimagebuild/writer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void create_preamble(
127127
cl_dir ent;
128128
ent.attrib = ATTR_DIRECTORY;
129129
ent.filesize = 0;
130+
ent.modified = 0;
130131
// . current directory
131132
memcpy((char*) ent.shortname, ". ", SHORTNAME_LEN);
132133
ent.cluster_hi = fsys.to_cluster_hi(self);
@@ -152,6 +153,7 @@ cl_dir create_entry(const std::string& name, uint8_t attr, uint32_t size)
152153
ent.cluster_hi = 0; /// SET THIS
153154
ent.cluster_lo = 0; /// SET THIS
154155
ent.filesize = size;
156+
ent.modified = 0;
155157
return ent;
156158
}
157159

@@ -163,6 +165,7 @@ void fill_unused(std::vector<cl_dir>& ents, int num)
163165
ent.cluster_hi = 0;
164166
ent.cluster_lo = 0;
165167
ent.filesize = 0;
168+
ent.modified = 0;
166169
while (num-- > 0) ents.push_back(ent);
167170
}
168171
void mod16_test(std::vector<cl_dir>& ents, int& mod16, int long_entries)
@@ -229,7 +232,11 @@ long Dir::write(FileSys& fsys, FILE* file, long pos, long parent)
229232
{
230233
cl_dir last;
231234
last.shortname[0] = 0x0; // last entry
232-
last.attrib = 0;
235+
last.cluster_hi = 0;
236+
last.cluster_lo = 0;
237+
last.attrib = 0;
238+
last.modified = 0;
239+
last.filesize = 0;
233240
ents.push_back(last);
234241
}
235242

src/drivers/virtioblk.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ void VirtioBlk::read (block_t blk, on_read_func func) {
231231
void VirtioBlk::read (block_t blk, size_t cnt, on_read_func func) {
232232

233233
// create big buffer for collecting all the disk data
234-
uint8_t* bufdata = new uint8_t[block_size() * cnt];
235-
buffer_t bigbuf { bufdata, std::default_delete<uint8_t[]>() };
234+
buffer_t bigbuf { new uint8_t[block_size() * cnt], std::default_delete<uint8_t[]>() };
236235
// (initialized) boolean array of partial jobs
237236
auto results = std::make_shared<size_t> (cnt);
238237
bool shipped = false;

0 commit comments

Comments
 (0)