File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -205,14 +205,18 @@ for field in struct.fields_in_declaration_order() {
205205 // Increase the current offset so that it's a multiple of the alignment
206206 // of this field. For the first field, this will always be zero.
207207 // The skipped bytes are called padding bytes.
208- current_offset += field.alignment % current_offset;
208+ //
209+ // padding_needed_for() is equivalent to
210+ // std::alloc::Layout::padding_needed_for(), but takes an integer rather
211+ // than a Layout as the first argument.
212+ current_offset += padding_needed_for(current_offset, field.alignment);
209213
210214 struct[field].offset = current_offset;
211215
212216 current_offset += field.size;
213217}
214218
215- struct.size = current_offset + current_offset % struct.alignment;
219+ struct.size = current_offset + padding_needed_for( current_offset, struct.alignment) ;
216220```
217221
218222> Note: This algorithm can produce zero-sized structs. This differs from
You can’t perform that action at this time.
0 commit comments