| ... | @@ -1870,18 +1870,15 @@ pub const LoadCommandIterator = struct { | ... | @@ -1870,18 +1870,15 @@ pub const LoadCommandIterator = struct { |
| 1870 | | 1870 | |
| 1871 | pub fn cast(lc: LoadCommand, comptime Cmd: type) ?Cmd { | 1871 | pub fn cast(lc: LoadCommand, comptime Cmd: type) ?Cmd { |
| 1872 | if (lc.data.len < @sizeOf(Cmd)) return null; | 1872 | if (lc.data.len < @sizeOf(Cmd)) return null; |
| 1873 | return @as(*const Cmd, @ptrCast(@alignCast(&lc.data[0]))).*; | 1873 | return @as(*align(1) const Cmd, @ptrCast(lc.data.ptr)).*; |
| 1874 | } | 1874 | } |
| 1875 | | 1875 | |
| 1876 | /// Asserts LoadCommand is of type segment_command_64. | 1876 | /// Asserts LoadCommand is of type segment_command_64. |
| 1877 | pub fn getSections(lc: LoadCommand) []const section_64 { | 1877 | pub fn getSections(lc: LoadCommand) []align(1) const section_64 { |
| 1878 | const segment_lc = lc.cast(segment_command_64).?; | 1878 | const segment_lc = lc.cast(segment_command_64).?; |
| 1879 | if (segment_lc.nsects == 0) return &[0]section_64{}; | 1879 | if (segment_lc.nsects == 0) return &[0]section_64{}; |
| 1880 | const data = lc.data[@sizeOf(segment_command_64)..]; | 1880 | const data = lc.data[@sizeOf(segment_command_64)..]; |
| 1881 | const sections = @as( | 1881 | const sections = @as([*]align(1) const section_64, @ptrCast(data.ptr))[0..segment_lc.nsects]; |
| 1882 | [*]const section_64, | | |
| 1883 | @ptrCast(@alignCast(&data[0])), | | |
| 1884 | )[0..segment_lc.nsects]; | | |
| 1885 | return sections; | 1882 | return sections; |
| 1886 | } | 1883 | } |
| 1887 | | 1884 | |
| ... | @@ -1900,12 +1897,12 @@ pub const LoadCommandIterator = struct { | ... | @@ -1900,12 +1897,12 @@ pub const LoadCommandIterator = struct { |
| 1900 | } | 1897 | } |
| 1901 | | 1898 | |
| 1902 | /// Asserts LoadCommand is of type build_version_command. | 1899 | /// Asserts LoadCommand is of type build_version_command. |
| 1903 | pub fn getBuildVersionTools(lc: LoadCommand) []const build_tool_version { | 1900 | pub fn getBuildVersionTools(lc: LoadCommand) []align(1) const build_tool_version { |
| 1904 | const build_lc = lc.cast(build_version_command).?; | 1901 | const build_lc = lc.cast(build_version_command).?; |
| 1905 | const ntools = build_lc.ntools; | 1902 | const ntools = build_lc.ntools; |
| 1906 | if (ntools == 0) return &[0]build_tool_version{}; | 1903 | if (ntools == 0) return &[0]build_tool_version{}; |
| 1907 | const data = lc.data[@sizeOf(build_version_command)..]; | 1904 | const data = lc.data[@sizeOf(build_version_command)..]; |
| 1908 | const tools = @as([*]const build_tool_version, @ptrCast(@alignCast(&data[0])))[0..ntools]; | 1905 | const tools = @as([*]align(1) const build_tool_version, @ptrCast(data.ptr))[0..ntools]; |
| 1909 | return tools; | 1906 | return tools; |
| 1910 | } | 1907 | } |
| 1911 | }; | 1908 | }; |
| ... | @@ -1913,16 +1910,13 @@ pub const LoadCommandIterator = struct { | ... | @@ -1913,16 +1910,13 @@ pub const LoadCommandIterator = struct { |
| 1913 | pub fn next(it: *LoadCommandIterator) ?LoadCommand { | 1910 | pub fn next(it: *LoadCommandIterator) ?LoadCommand { |
| 1914 | if (it.index >= it.ncmds) return null; | 1911 | if (it.index >= it.ncmds) return null; |
| 1915 | | 1912 | |
| 1916 | const hdr = @as( | 1913 | const hdr = @as(*align(1) const load_command, @ptrCast(it.buffer.ptr)).*; |
| 1917 | *const load_command, | | |
| 1918 | @ptrCast(@alignCast(&it.buffer[0])), | | |
| 1919 | ).*; | | |
| 1920 | const cmd = LoadCommand{ | 1914 | const cmd = LoadCommand{ |
| 1921 | .hdr = hdr, | 1915 | .hdr = hdr, |
| 1922 | .data = it.buffer[0..hdr.cmdsize], | 1916 | .data = it.buffer[0..hdr.cmdsize], |
| 1923 | }; | 1917 | }; |
| 1924 | | 1918 | |
| 1925 | it.buffer = @alignCast(it.buffer[hdr.cmdsize..]); | 1919 | it.buffer = it.buffer[hdr.cmdsize..]; |
| 1926 | it.index += 1; | 1920 | it.index += 1; |
| 1927 | | 1921 | |
| 1928 | return cmd; | 1922 | return cmd; |