File tree 1 file changed +6
-2
lines changed
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() {
205
205
// Increase the current offset so that it's a multiple of the alignment
206
206
// of this field. For the first field, this will always be zero.
207
207
// 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);
209
213
210
214
struct[field].offset = current_offset;
211
215
212
216
current_offset += field.size;
213
217
}
214
218
215
- struct.size = current_offset + current_offset % struct.alignment;
219
+ struct.size = current_offset + padding_needed_for( current_offset, struct.alignment) ;
216
220
```
217
221
218
222
> Note: This algorithm can produce zero-sized structs. This differs from
You can’t perform that action at this time.
0 commit comments