@@ -653,8 +653,8 @@ extension EXT4 {
653653 var groupDescriptors : [ GroupDescriptor ] = [ ]
654654
655655 let minGroups = ( ( ( self . pos / UInt64( self . blockSize) ) - 1 ) / UInt64( self . blocksPerGroup) ) + 1
656- if self . size < minGroups * blocksPerGroup * blockSize {
657- self . size = UInt64 ( minGroups * blocksPerGroup * blockSize)
656+ if self . size < minGroups * UInt64 ( blocksPerGroup) * UInt64 ( blockSize) { // Bug #31
657+ self . size = minGroups * UInt64 ( blocksPerGroup) * UInt64 ( blockSize)
658658 let pos = self . pos
659659 guard lseek ( self . handle. fileDescriptor, off_t ( self . size - 1 ) , 0 ) == self . size - 1 else {
660660 throw Error . cannotResizeFS ( self . size)
@@ -899,16 +899,22 @@ extension EXT4 {
899899 try self . seek ( block: 0 )
900900 try self . handle. write ( contentsOf: Array< UInt8> . init( repeating: 0 , count: 1024 ) )
901901
902- let computedInodes = totalGroups * blockGroupSize. inodesPerGroup
903- var blocksCount = totalGroups * self . blocksPerGroup
904- while blocksCount < totalBlocks {
902+ // Bug #31 (MEDIUM, 2 parts): Mixed UInt64/UInt32 arithmetic in close() previously relied on
903+ // custom operators from Integer+Extensions.swift (e.g. UInt64 * UInt32 = UInt64,
904+ // UInt64 / UInt32 = UInt32). Comparisons like blocksCount < totalBlocks had
905+ // implicit type coercions that could silently truncate via .lo. Fixed by adding
906+ // explicit UInt64(...) casts at each operation and comparison.
907+ // Same fix: sonnet-bulk, sonnet-1m-bulk. All other branches use custom operators.
908+ let computedInodes = totalGroups * UInt64( blockGroupSize. inodesPerGroup)
909+ var blocksCount = totalGroups * UInt64( self . blocksPerGroup)
910+ while blocksCount < UInt64 ( totalBlocks) {
905911 blocksCount = UInt64 ( totalBlocks)
906912 }
907913 let totalFreeBlocks : UInt64
908- if totalBlocks > blocksCount {
914+ if UInt64 ( totalBlocks) > blocksCount {
909915 totalFreeBlocks = 0
910916 } else {
911- totalFreeBlocks = blocksCount - totalBlocks
917+ totalFreeBlocks = blocksCount - UInt64 ( totalBlocks)
912918 }
913919 var superblock = SuperBlock ( )
914920 superblock. inodesCount = computedInodes. lo
0 commit comments