Avoid undefined behavior in color table hashing.
* image.c (CT_HASH_RGB) [COLOR_TABLE_SUPPORT]: Remove, replacing with ... (ct_hash_rgb) [COLOR_TABLE_SUPPORT]: New function. All uses changed. This function avoids undefined behavior with signed shift overflow.
This commit is contained in:
parent
5531e676d4
commit
911ad4a15e
2 changed files with 13 additions and 2 deletions
|
@ -1,3 +1,10 @@
|
|||
2014-11-13 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
||||
Avoid undefined behavior in color table hashing.
|
||||
* image.c (CT_HASH_RGB) [COLOR_TABLE_SUPPORT]: Remove, replacing with ...
|
||||
(ct_hash_rgb) [COLOR_TABLE_SUPPORT]: New function. All uses changed.
|
||||
This function avoids undefined behavior with signed shift overflow.
|
||||
|
||||
2014-11-10 Eli Zaretskii <eliz@gnu.org>
|
||||
|
||||
* fileio.c (Finsert_file_contents): Invalidate buffer caches also
|
||||
|
|
|
@ -4294,7 +4294,11 @@ struct ct_color
|
|||
|
||||
/* Value is a hash of the RGB color given by R, G, and B. */
|
||||
|
||||
#define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B))
|
||||
static unsigned
|
||||
ct_hash_rgb (unsigned r, unsigned g, unsigned b)
|
||||
{
|
||||
return (r << 16) ^ (g << 8) ^ b;
|
||||
}
|
||||
|
||||
/* The color hash table. */
|
||||
|
||||
|
@ -4349,7 +4353,7 @@ free_color_table (void)
|
|||
static unsigned long
|
||||
lookup_rgb_color (struct frame *f, int r, int g, int b)
|
||||
{
|
||||
unsigned hash = CT_HASH_RGB (r, g, b);
|
||||
unsigned hash = ct_hash_rgb (r, g, b);
|
||||
int i = hash % CT_SIZE;
|
||||
struct ct_color *p;
|
||||
Display_Info *dpyinfo;
|
||||
|
|
Loading…
Add table
Reference in a new issue