+ {
+ size_t lhs;
+ size_t rhs;
+
+ /* lhs = segment_count * segment_command_sz */
+ if (os_mul_overflow(segment_count, segment_command_sz, &lhs)) {
+ error = ENOMEM;
+ goto out;
+ }
+
+ /* rhs = (tstate_size + sizeof(struct thread_command)) * thread_count */
+ if (os_add_and_mul_overflow(tstate_size, sizeof(struct thread_command), thread_count, &rhs)) {
+ error = ENOMEM;
+ goto out;
+ }
+
+ /* command_size = lhs + rhs */
+ if (os_add_overflow(lhs, rhs, &command_size)) {
+ error = ENOMEM;
+ goto out;
+ }
+ }
+
+ if (os_add_overflow(command_size, mach_header_sz, &header_size)) {
+ error = ENOMEM;
+ goto out;
+ }