aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2014-11-12 22:34:52 -0800
committerPaul Eggert2014-11-12 22:35:22 -0800
commit911ad4a15e284dec36f435f031a09cebc08b094d (patch)
treea9e517de7b2d05c3fd485616a5f829c967bfff9d
parent5531e676d43d4df0a6320ba2b03175d4a0aad86d (diff)
downloademacs-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.
-rw-r--r--src/ChangeLog7
-rw-r--r--src/image.c8
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 @@
12014-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
12014-11-10 Eli Zaretskii <eliz@gnu.org> 82014-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)) 4297static unsigned
4298ct_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)
4349static unsigned long 4353static unsigned long
4350lookup_rgb_color (struct frame *f, int r, int g, int b) 4354lookup_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;