#pragma pack(push) with no matching pop

ID

objectivec.correctness.pragma_pack_mismatch

Severity

low

Remediation Complexity

trivial

Remediation Risk

medium

Remediation Effort

low

Resource

Preprocessor

Language

Objective-C

Description

Reports a #pragma pack(push, …​) directive that no later #pragma pack(pop) directive balances in the same file. A push whose pop appears further down is not reported, and a pop written inside a comment or a string literal does not count as a match.

Rationale

Structure packing set by a push stays in force to the end of the translation unit, so every declaration below it - including the ones pulled in by headers imported afterwards - is laid out with the packed alignment rather than the natural one. Two translation units then disagree about the size and field offsets of the same structure, and the mismatch corrupts data across the boundary instead of failing to link.

The following code illustrates the pattern detected by this rule:

// FLAGGED: #pragma pack(push) with no matching pop
#pragma pack(push, 4)

Remediation

Add the matching #pragma pack(pop) immediately after the declarations that need the packed layout, so the alignment is restored before anything else is declared. Keep the pushed region as short as possible, and never leave one open across an #import.

Configuration

This detector does not need any configuration.

References

© 2026 Xygeni. All rights reserved