diff options
| author | Paul Eggert | 2014-04-27 18:29:44 -0700 |
|---|---|---|
| committer | Paul Eggert | 2014-04-27 18:29:44 -0700 |
| commit | 6ab1b16c54b63d1c4217b6fcea026400029fcc72 (patch) | |
| tree | e3fef3d5e3f4436b2bc59b1006afc98075da06f0 /src/alloc.c | |
| parent | 196bfaecb0caffcdbb699694139a97148e90e227 (diff) | |
| download | emacs-6ab1b16c54b63d1c4217b6fcea026400029fcc72.tar.gz emacs-6ab1b16c54b63d1c4217b6fcea026400029fcc72.zip | |
Avoid undefined behavior in signed left shift.
This ports to GCC 4.9.0 with -fsanitize=undefined.
* alloc.c (bool_vector_fill, SETMARKBIT, UNSETMARKBIT):
* data.c (Fash):
* regex.c (extract_number):
* lisp.h (make_number, XINT):
Do not shift a 1 bit left into a sign bit.
* alloc.c (struct cons_block, struct float_block): Use unsigned,
not int, for gcmarkbits. All uses changed.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/alloc.c b/src/alloc.c index 6bee0c990c4..32d3333cea8 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -2131,7 +2131,7 @@ bool_vector_fill (Lisp_Object a, Lisp_Object init) | |||
| 2131 | unsigned char *data = bool_vector_uchar_data (a); | 2131 | unsigned char *data = bool_vector_uchar_data (a); |
| 2132 | int pattern = NILP (init) ? 0 : (1 << BOOL_VECTOR_BITS_PER_CHAR) - 1; | 2132 | int pattern = NILP (init) ? 0 : (1 << BOOL_VECTOR_BITS_PER_CHAR) - 1; |
| 2133 | ptrdiff_t nbytes = bool_vector_bytes (nbits); | 2133 | ptrdiff_t nbytes = bool_vector_bytes (nbits); |
| 2134 | int last_mask = ~ (~0 << ((nbits - 1) % BOOL_VECTOR_BITS_PER_CHAR + 1)); | 2134 | int last_mask = ~ (~0u << ((nbits - 1) % BOOL_VECTOR_BITS_PER_CHAR + 1)); |
| 2135 | memset (data, pattern, nbytes - 1); | 2135 | memset (data, pattern, nbytes - 1); |
| 2136 | data[nbytes - 1] = pattern & last_mask; | 2136 | data[nbytes - 1] = pattern & last_mask; |
| 2137 | } | 2137 | } |
| @@ -2336,17 +2336,17 @@ make_formatted_string (char *buf, const char *format, ...) | |||
| 2336 | / (sizeof (struct Lisp_Float) * CHAR_BIT + 1)) | 2336 | / (sizeof (struct Lisp_Float) * CHAR_BIT + 1)) |
| 2337 | 2337 | ||
| 2338 | #define GETMARKBIT(block,n) \ | 2338 | #define GETMARKBIT(block,n) \ |
| 2339 | (((block)->gcmarkbits[(n) / (sizeof (int) * CHAR_BIT)] \ | 2339 | (((block)->gcmarkbits[(n) / (sizeof (unsigned) * CHAR_BIT)] \ |
| 2340 | >> ((n) % (sizeof (int) * CHAR_BIT))) \ | 2340 | >> ((n) % (sizeof (unsigned) * CHAR_BIT))) \ |
| 2341 | & 1) | 2341 | & 1) |
| 2342 | 2342 | ||
| 2343 | #define SETMARKBIT(block,n) \ | 2343 | #define SETMARKBIT(block,n) \ |
| 2344 | (block)->gcmarkbits[(n) / (sizeof (int) * CHAR_BIT)] \ | 2344 | ((block)->gcmarkbits[(n) / (sizeof (unsigned) * CHAR_BIT)] \ |
| 2345 | |= 1 << ((n) % (sizeof (int) * CHAR_BIT)) | 2345 | |= 1u << ((n) % (sizeof (unsigned) * CHAR_BIT))) |
| 2346 | 2346 | ||
| 2347 | #define UNSETMARKBIT(block,n) \ | 2347 | #define UNSETMARKBIT(block,n) \ |
| 2348 | (block)->gcmarkbits[(n) / (sizeof (int) * CHAR_BIT)] \ | 2348 | ((block)->gcmarkbits[(n) / (sizeof (unsigned) * CHAR_BIT)] \ |
| 2349 | &= ~(1 << ((n) % (sizeof (int) * CHAR_BIT))) | 2349 | &= ~(1u << ((n) % (sizeof (unsigned) * CHAR_BIT)))) |
| 2350 | 2350 | ||
| 2351 | #define FLOAT_BLOCK(fptr) \ | 2351 | #define FLOAT_BLOCK(fptr) \ |
| 2352 | ((struct float_block *) (((uintptr_t) (fptr)) & ~(BLOCK_ALIGN - 1))) | 2352 | ((struct float_block *) (((uintptr_t) (fptr)) & ~(BLOCK_ALIGN - 1))) |
| @@ -2358,7 +2358,7 @@ struct float_block | |||
| 2358 | { | 2358 | { |
| 2359 | /* Place `floats' at the beginning, to ease up FLOAT_INDEX's job. */ | 2359 | /* Place `floats' at the beginning, to ease up FLOAT_INDEX's job. */ |
| 2360 | struct Lisp_Float floats[FLOAT_BLOCK_SIZE]; | 2360 | struct Lisp_Float floats[FLOAT_BLOCK_SIZE]; |
| 2361 | int gcmarkbits[1 + FLOAT_BLOCK_SIZE / (sizeof (int) * CHAR_BIT)]; | 2361 | unsigned gcmarkbits[1 + FLOAT_BLOCK_SIZE / (sizeof (unsigned) * CHAR_BIT)]; |
| 2362 | struct float_block *next; | 2362 | struct float_block *next; |
| 2363 | }; | 2363 | }; |
| 2364 | 2364 | ||
| @@ -2452,7 +2452,7 @@ struct cons_block | |||
| 2452 | { | 2452 | { |
| 2453 | /* Place `conses' at the beginning, to ease up CONS_INDEX's job. */ | 2453 | /* Place `conses' at the beginning, to ease up CONS_INDEX's job. */ |
| 2454 | struct Lisp_Cons conses[CONS_BLOCK_SIZE]; | 2454 | struct Lisp_Cons conses[CONS_BLOCK_SIZE]; |
| 2455 | int gcmarkbits[1 + CONS_BLOCK_SIZE / (sizeof (int) * CHAR_BIT)]; | 2455 | unsigned gcmarkbits[1 + CONS_BLOCK_SIZE / (sizeof (unsigned) * CHAR_BIT)]; |
| 2456 | struct cons_block *next; | 2456 | struct cons_block *next; |
| 2457 | }; | 2457 | }; |
| 2458 | 2458 | ||