Skip to content

Commit db777e9

Browse files
committed
Fix shifting signed values too far
Signed shift of 31 for int and 63 for long is flagged as undefined behavior by UBSan (-fsanitize=undefined) and seems to be indeed so according to the standard. The patch converts such cases to use unsigned.
1 parent f651397 commit db777e9

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

Zend/zend_alloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,12 @@ static zend_always_inline int zend_mm_bitset_is_set(zend_mm_bitset *bitset, int
587587

588588
static zend_always_inline void zend_mm_bitset_set_bit(zend_mm_bitset *bitset, int bit)
589589
{
590-
bitset[bit / ZEND_MM_BITSET_LEN] |= (Z_L(1) << (bit & (ZEND_MM_BITSET_LEN-1)));
590+
bitset[bit / ZEND_MM_BITSET_LEN] |= (Z_UL(1) << (bit & (ZEND_MM_BITSET_LEN-1)));
591591
}
592592

593593
static zend_always_inline void zend_mm_bitset_reset_bit(zend_mm_bitset *bitset, int bit)
594594
{
595-
bitset[bit / ZEND_MM_BITSET_LEN] &= ~(Z_L(1) << (bit & (ZEND_MM_BITSET_LEN-1)));
595+
bitset[bit / ZEND_MM_BITSET_LEN] &= ~(Z_UL(1) << (bit & (ZEND_MM_BITSET_LEN-1)));
596596
}
597597

598598
static zend_always_inline void zend_mm_bitset_set_range(zend_mm_bitset *bitset, int start, int len)

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ typedef struct _zend_oparray_context {
329329
#define ZEND_ACC_DTOR (1 << 29) /* | X | | */
330330
/* | | | */
331331
/* op_array uses strict mode types | | | */
332-
#define ZEND_ACC_STRICT_TYPES (1 << 31) /* | X | | */
332+
#define ZEND_ACC_STRICT_TYPES (1U << 31) /* | X | | */
333333

334334

335335
#define ZEND_ACC_PPP_MASK (ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE)

Zend/zend_cpuinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "zend.h"
2323

2424
#define ZEND_CPU_EBX_MASK (1<<30)
25-
#define ZEND_CPU_EDX_MASK (1<<31)
25+
#define ZEND_CPU_EDX_MASK (1U<<31)
2626

2727
typedef enum _zend_cpu_feature {
2828
/* ECX */

ext/opcache/Optimizer/zend_cfg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define ZEND_BB_LOOP_HEADER (1<<16)
3636
#define ZEND_BB_IRREDUCIBLE_LOOP (1<<17)
3737

38-
#define ZEND_BB_REACHABLE (1<<31)
38+
#define ZEND_BB_REACHABLE (1U<<31)
3939

4040
#define ZEND_BB_PROTECTED (ZEND_BB_ENTRY|ZEND_BB_RECV_ENTRY|ZEND_BB_TRY|ZEND_BB_CATCH|ZEND_BB_FINALLY|ZEND_BB_FINALLY_END|ZEND_BB_UNREACHABLE_FREE)
4141

@@ -92,7 +92,7 @@ typedef struct _zend_cfg {
9292
} zend_cfg;
9393

9494
/* Build Flags */
95-
#define ZEND_RT_CONSTANTS (1<<31)
95+
#define ZEND_RT_CONSTANTS (1U<<31)
9696
#define ZEND_CFG_STACKLESS (1<<30)
9797
#define ZEND_SSA_DEBUG_LIVENESS (1<<29)
9898
#define ZEND_SSA_DEBUG_PHI_PLACEMENT (1<<28)

0 commit comments

Comments
 (0)