cbmem_console: Fix undefined behavior

Fixes report found by undefined behavior sanitizer. Left shifting an int
where the right operand is >= width of type is undefined. Add
ul suffix since it's safe for unsigned types.

Change-Id: I4b2365428e421085285006bc1ea8aea75890ff65
Signed-off-by: Ryan Salsamendi <rsalsamendi@hotmail.com>
Reviewed-on: https://review.coreboot.org/20144
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Philippe Mathieu-Daudé <philippe.mathieu.daude@gmail.com>
Reviewed-by: Martin Roth <martinroth@google.com>
Reviewed-by: Youness Alaoui <snifikino@gmail.com>
This commit is contained in:
Ryan Salsamendi 2017-06-09 19:47:57 -07:00 committed by Patrick Georgi
parent f0b0712023
commit fce582fa1c
1 changed files with 1 additions and 1 deletions

View File

@ -47,7 +47,7 @@ struct cbmem_console {
#define MAX_SIZE (1 << 28) /* can't be changed without breaking readers! */ #define MAX_SIZE (1 << 28) /* can't be changed without breaking readers! */
#define CURSOR_MASK (MAX_SIZE - 1) /* bits 31-28 are reserved for flags */ #define CURSOR_MASK (MAX_SIZE - 1) /* bits 31-28 are reserved for flags */
#define OVERFLOW (1 << 31) /* set if in ring-buffer mode */ #define OVERFLOW (1UL << 31) /* set if in ring-buffer mode */
_Static_assert(CONFIG_CONSOLE_CBMEM_BUFFER_SIZE <= MAX_SIZE, _Static_assert(CONFIG_CONSOLE_CBMEM_BUFFER_SIZE <= MAX_SIZE,
"cbmem_console format cannot support buffers larger than 256MB!"); "cbmem_console format cannot support buffers larger than 256MB!");