@@ -41,7 +41,7 @@ CompoundFileReader::CompoundFileReader(const void *buffer,
4141
4242 m_sector_size = m_hdr->major_version == 3 ? 512 : 4096 ;
4343
44- // The file must contains at least 3 sectors
44+ // The file must contain at least 3 sectors
4545 if (m_buffer_len < m_sector_size * 3 ) {
4646 throw CfbFileCorrupted ();
4747 }
@@ -54,7 +54,8 @@ CompoundFileReader::CompoundFileReader(const void *buffer,
5454 m_mini_stream_start_sector = root->start_sector_location ;
5555}
5656
57- const CompoundFileEntry *CompoundFileReader::get_entry (size_t entry_id) const {
57+ const CompoundFileEntry *
58+ CompoundFileReader::get_entry (const std::size_t entry_id) const {
5859 if (entry_id == 0xFFFFFFFF ) {
5960 return nullptr ;
6061 }
@@ -94,9 +95,9 @@ void CompoundFileReader::read_file(const CompoundFileEntry *entry,
9495}
9596
9697void CompoundFileReader::enum_files (const CompoundFileEntry *entry,
97- int max_level,
98+ const int max_level,
9899 const EnumFilesCallback &callback) const {
99- std::u16string dir;
100+ const std::u16string dir;
100101 enum_nodes (get_entry (entry->child_id ), 0 , max_level, dir, callback);
101102}
102103
@@ -114,10 +115,10 @@ void CompoundFileReader::enum_nodes(const CompoundFileEntry *entry,
114115
115116 callback (entry, dir, current_level + 1 );
116117
117- const CompoundFileEntry *child = get_entry (entry->child_id );
118- if ( child != nullptr ) {
118+ if ( const CompoundFileEntry *child = get_entry (entry->child_id );
119+ child != nullptr ) {
119120 std::u16string new_dir = dir;
120- if (dir.length () != 0 ) {
121+ if (! dir.empty () ) {
121122 new_dir.push_back (' /' );
122123 }
123124 new_dir.append (reinterpret_cast <const char16_t *>(entry->name ),
@@ -141,7 +142,7 @@ void CompoundFileReader::read_stream(std::size_t sector, std::size_t offset,
141142 // --> m_sectorSize --> ... --> remaining
142143 while (len > 0 ) {
143144 const std::uint8_t *src = sector_offset_to_address (sector, offset);
144- std::size_t copylen = std::min (len, m_sector_size - offset);
145+ const std::size_t copylen = std::min (len, m_sector_size - offset);
145146 if (m_buffer + m_buffer_len < src + copylen) {
146147 throw CfbFileCorrupted ();
147148 }
@@ -164,7 +165,7 @@ void CompoundFileReader::read_mini_stream(std::size_t sector,
164165 // --> m_sectorSize --> ... --> remaining
165166 while (len > 0 ) {
166167 const std::uint8_t *src = mini_sector_offset_to_address (sector, offset);
167- std::size_t copylen = std::min (len, m_mini_sector_size - offset);
168+ const std::size_t copylen = std::min (len, m_mini_sector_size - offset);
168169 if (m_buffer + m_buffer_len < src + copylen) {
169170 throw CfbFileCorrupted ();
170171 }
@@ -177,25 +178,28 @@ void CompoundFileReader::read_mini_stream(std::size_t sector,
177178 }
178179}
179180
180- std::size_t CompoundFileReader::get_next_sector (size_t sector) const {
181+ std::size_t
182+ CompoundFileReader::get_next_sector (const std::size_t sector) const {
181183 // lookup FAT
182- std::size_t entriesPerSector = m_sector_size / 4 ;
183- std::size_t fatSectorNumber = sector / entriesPerSector;
184- std::size_t fatSectorLocation = get_fat_sector_location (fatSectorNumber);
184+ const std::size_t entriesPerSector = m_sector_size / 4 ;
185+ const std::size_t fatSectorNumber = sector / entriesPerSector;
186+ const std::size_t fatSectorLocation =
187+ get_fat_sector_location (fatSectorNumber);
185188 return parse_uint32 (sector_offset_to_address (fatSectorLocation,
186189 sector % entriesPerSector * 4 ));
187190}
188191
189- std::size_t CompoundFileReader::get_next_mini_sector (size_t mini_sector) const {
192+ std::size_t
193+ CompoundFileReader::get_next_mini_sector (const std::size_t mini_sector) const {
190194 std::size_t sector, offset;
191195 locate_final_sector (m_hdr->first_mini_fat_sector_location , mini_sector * 4 ,
192196 §or, &offset);
193197 return parse_uint32 (sector_offset_to_address (sector, offset));
194198}
195199
196200const std::uint8_t *
197- CompoundFileReader::sector_offset_to_address (size_t sector,
198- size_t offset) const {
201+ CompoundFileReader::sector_offset_to_address (const std:: size_t sector,
202+ const std:: size_t offset) const {
199203 if (sector >= MAX_REG_SECT || offset >= m_sector_size ||
200204 m_buffer_len <= static_cast <std::uint64_t >(m_sector_size) * sector +
201205 m_sector_size + offset) {
@@ -249,7 +253,7 @@ std::size_t CompoundFileReader::get_fat_sector_location(
249253 }
250254
251255 fat_sector_number -= 109 ;
252- std::size_t entriesPerSector = m_sector_size / 4 - 1 ;
256+ const std::size_t entriesPerSector = m_sector_size / 4 - 1 ;
253257 std::size_t difatSectorLocation = m_hdr->first_difat_sector_location ;
254258 while (fat_sector_number >= entriesPerSector) {
255259 fat_sector_number -= entriesPerSector;
@@ -273,15 +277,18 @@ PropertySet::PropertySet(const void *buffer, const std::size_t len,
273277 }
274278}
275279
276- const std::uint16_t *PropertySet::get_string_property (uint32_t property_id) {
280+ const std::uint16_t *
281+ PropertySet::get_string_property (const std::uint32_t property_id) {
277282 for (std::uint32_t i = 0 ; i < m_hdr->num_properties ; i++) {
278283 if (m_hdr->property_identifier_and_offset [i].id == property_id) {
279- std::uint32_t offset = m_hdr->property_identifier_and_offset [i].offset ;
284+ const std::uint32_t offset =
285+ m_hdr->property_identifier_and_offset [i].offset ;
280286 if (m_buffer_len < offset + 8 ) {
281287 throw CfbFileCorrupted ();
282288 }
283- std::uint32_t stringLengthInChar = parse_uint32 (m_buffer + offset + 4 );
284- if (m_buffer_len < offset + 8 + stringLengthInChar * 2 ) {
289+ if (const std::uint32_t stringLengthInChar =
290+ parse_uint32 (m_buffer + offset + 4 );
291+ m_buffer_len < offset + 8 + stringLengthInChar * 2 ) {
285292 throw CfbFileCorrupted ();
286293 }
287294 return reinterpret_cast <const std::uint16_t *>(m_buffer + offset + 8 );
@@ -307,15 +314,15 @@ std::size_t PropertySetStream::get_property_set_count() {
307314 return m_hdr->num_property_sets ;
308315}
309316
310- PropertySet PropertySetStream::get_property_set (size_t index) {
317+ PropertySet PropertySetStream::get_property_set (const std:: size_t index) {
311318 if (index >= get_property_set_count ()) {
312319 throw CfbFileCorrupted ();
313320 }
314- std::uint32_t offset = m_hdr->property_set_info [index].offset ;
321+ const std::uint32_t offset = m_hdr->property_set_info [index].offset ;
315322 if (m_buffer_len < offset + 4 ) {
316323 throw CfbFileCorrupted ();
317324 }
318- std::uint32_t size = parse_uint32 (m_buffer + offset);
325+ const std::uint32_t size = parse_uint32 (m_buffer + offset);
319326 if (m_buffer_len < offset + size) {
320327 throw CfbFileCorrupted ();
321328 }
0 commit comments