Skip to content

Subtract underflow when generating explicit paddings #2695

Closed
@yshui

Description

@yshui

Input C/C++ Header

#pragma pack(2)

struct Test {
        unsigned long x;
        char a;
        char b;
        char c;
};

Bindgen Invocation

$ bindgen input.h --explicit-padding

Actual Results

panicked at bindgen/codegen/struct_layout.rs:309:20:
attempt to subtract with overflow

Analysis

The reason this happens is because in saw_field_with_layout, padding bytes size is always calculated using the specified pack alignment, i.e. 2 bytes. however, if the field itself has a smaller alignment requirement, that should be used instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions