Skip to content

Commit 56501fb

Browse files
committed
util: Add s390 31 bit mode support
Even though size_t is of the same size as a uint32_t, the s390 architecture is a bit picky about its 31 bit mode with size_t. Use custom code to fix this issue in a rather architecture independent but unfortunately slower way for s390 31 bit mode. Reference: #402 Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
1 parent ca9a7f4 commit 56501fb

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

shared/util.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,15 @@ static inline bool uaddsz_overflow(size_t a, size_t b, size_t *res)
123123
#if __SIZEOF_SIZE_T__ == 8
124124
return uadd64_overflow(a, b, res);
125125
#elif __SIZEOF_SIZE_T__ == 4
126+
#ifdef __s390__
127+
if (b < SIZE_MAX - a) {
128+
*res = a + b;
129+
return true;
130+
}
131+
return false;
132+
#else
126133
return uadd32_overflow(a, b, res);
134+
#endif
127135
#else
128136
#error "Unknown sizeof(size_t)"
129137
#endif
@@ -167,7 +175,15 @@ static inline bool umulsz_overflow(size_t a, size_t b, size_t *res)
167175
#if __SIZEOF_SIZE_T__ == 8
168176
return umul64_overflow(a, b, res);
169177
#elif __SIZEOF_SIZE_T__ == 4
178+
#ifdef __s390__
179+
if (a == 0 || b <= SIZE_MAX / a) {
180+
*res = a * b;
181+
return true;
182+
}
183+
return false;
184+
#else
170185
return umul32_overflow(a, b, res);
186+
#endif
171187
#else
172188
#error "Unknown sizeof(size_t)"
173189
#endif

0 commit comments

Comments
 (0)