Skip to content

Fix alignment bug caused by empty objects - #103

Merged
mikee47 merged 2 commits into
developfrom
fix/empty-objects
Aug 20, 2026
Merged

Fix alignment bug caused by empty objects#103
mikee47 merged 2 commits into
developfrom
fix/empty-objects

Conversation

@mikee47

@mikee47 mikee47 commented Aug 20, 2026

Copy link
Copy Markdown
Owner

This PR fixes a bug demonstrated by the following schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "empty": {
      "type": "object",
      "description": "Must preceded 'guard' for checking struct alignment"
    },
    "guard": {
      "type": "integer",
      "default": 555
    }
  }
}

The struct which provides default values is generated as:

struct __attribute__((packed)) Struct {
    ContainedEmpty::Struct empty{};
    int32_t guard{555};
};

Because C++ allocates one byte to empty structures, guard is misaligned.

The code generator is now updated so that empty structs are omitted entirely:

struct __attribute__((packed)) Struct {
    int32_t guard{555};
};

@mikee47 mikee47 added the bug Something isn't working label Aug 20, 2026
@mikee47
mikee47 merged commit 4812902 into develop Aug 20, 2026
18 checks passed
@mikee47
mikee47 deleted the fix/empty-objects branch August 20, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant