diff options
| author | Paul Eggert | 2014-11-12 22:34:52 -0800 |
|---|---|---|
| committer | Paul Eggert | 2014-11-12 22:35:22 -0800 |
| commit | 911ad4a15e284dec36f435f031a09cebc08b094d (patch) | |
| tree | a9e517de7b2d05c3fd485616a5f829c967bfff9d /src | |
| parent | 5531e676d43d4df0a6320ba2b03175d4a0aad86d (diff) | |
| download | emacs-911ad4a15e284dec36f435f031a09cebc08b094d.tar.gz emacs-911ad4a15e284dec36f435f031a09cebc08b094d.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/image.c | 8 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index d44de652dde..2be24fa851b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2014-11-13 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Avoid undefined behavior in color table hashing. | ||
| 4 | * image.c (CT_HASH_RGB) [COLOR_TABLE_SUPPORT]: Remove, replacing with ... | ||
| 5 | (ct_hash_rgb) [COLOR_TABLE_SUPPORT]: New function. All uses changed. | ||
| 6 | This function avoids undefined behavior with signed shift overflow. | ||
| 7 | |||
| 1 | 2014-11-10 Eli Zaretskii <eliz@gnu.org> | 8 | 2014-11-10 Eli Zaretskii <eliz@gnu.org> |
| 2 | 9 | ||
| 3 | * fileio.c (Finsert_file_contents): Invalidate buffer caches also | 10 | * fileio.c (Finsert_file_contents): Invalidate buffer caches also |
diff --git a/src/image.c b/src/image.c index 4b73a5fe80c..1a2c0e29dde 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -4294,7 +4294,11 @@ struct ct_color | |||
| 4294 | 4294 | ||
| 4295 | /* Value is a hash of the RGB color given by R, G, and B. */ | 4295 | /* Value is a hash of the RGB color given by R, G, and B. */ |
| 4296 | 4296 | ||
| 4297 | #define CT_HASH_RGB(R, G, B) (((R) << 16) ^ ((G) << 8) ^ (B)) | 4297 | static unsigned |
| 4298 | ct_hash_rgb (unsigned r, unsigned g, unsigned b) | ||
| 4299 | { | ||
| 4300 | return (r << 16) ^ (g << 8) ^ b; | ||
| 4301 | } | ||
| 4298 | 4302 | ||
| 4299 | /* The color hash table. */ | 4303 | /* The color hash table. */ |
| 4300 | 4304 | ||
| @@ -4349,7 +4353,7 @@ free_color_table (void) | |||
| 4349 | static unsigned long | 4353 | static unsigned long |
| 4350 | lookup_rgb_color (struct frame *f, int r, int g, int b) | 4354 | lookup_rgb_color (struct frame *f, int r, int g, int b) |
| 4351 | { | 4355 | { |
| 4352 | unsigned hash = CT_HASH_RGB (r, g, b); | 4356 | unsigned hash = ct_hash_rgb (r, g, b); |
| 4353 | int i = hash % CT_SIZE; | 4357 | int i = hash % CT_SIZE; |
| 4354 | struct ct_color *p; | 4358 | struct ct_color *p; |
| 4355 | Display_Info *dpyinfo; | 4359 | Display_Info *dpyinfo; |