Skip to content

Commit 8bfde5d

Browse files
authored
Fix shift out of bounds on 32-bit non-fast-path platforms (#10941)
The x86-32 build uses a fast path, but when I disabled the fast path I got the following compile error with -Werror: mysqlnd_portability.h:221:95: error: right shift count >= width of type [-Werror=shift-count-overflow] For 32-bit platforms that don't have the fast path, this can cause undefined behaviour at runtime. Some CPUs just mask the shift amount so in those cases you even get wrong results. This is not always found during the build because -Werror is off by default.
1 parent c89d797 commit 8bfde5d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ext/mysqlnd/mysqlnd_portability.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ typedef union {
215215
*(((char *)(T))+1) = (char)(((A) >> 8));\
216216
*(((char *)(T))+2) = (char)(((A) >> 16));\
217217
*(((char *)(T))+3) = (char)(((A) >> 24)); \
218-
*(((char *)(T))+4) = (char)(((A) >> 32)); } while (0)
219-
#define int8store(T,A) { uint32_t def_temp= (uint32_t) (A), def_temp2= (uint32_t) ((A) >> 32); \
218+
*(((char *)(T))+4) = sizeof(A) == 4 ? 0 : (char)(((A) >> 32)); } while (0)
219+
#define int8store(T,A) { uint32_t def_temp= (uint32_t) (A), def_temp2= sizeof(A) == 4 ? 0 : (uint32_t) ((A) >> 32); \
220220
int4store((T),def_temp); \
221221
int4store((T+4),def_temp2); \
222222
}

0 commit comments

Comments
 (0)