Tk Source Code

View Ticket
Login
Ticket UUID: 2911570
Title: Color hash problem on x86_64
Type: Bug Version: obsolete: 8.5.7
Submitter: Created on: 2009-12-09 18:17:47
Subsystem: 30. Color Names Assigned To: dkf
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-12-10 05:43:15
Resolution: Fixed Closed By: dkf
    Closed on: 2009-12-09 22:43:15
Description:
Description of problem:
A stack-allocated structure is used as a hash key for a color in
Tk_GetColorByValue(). Compilation on x86_64 inserts some unused gaps in
structures for alignment: this results in having undefined bits participating
to the hash code computation, introducing the risk of missing a color that is
already in the table.

Version-Release number of selected component (if applicable):
tk-8.5.7-2.fc12.x86_64

How reproducible:
No recipe: very random in nature.
I discovered this problem inadvertently while using valgrind on "insight" for
another problem.

Additional info:
The attached patch fixes this problem by clearing the structure before
assigning its fields.  

---------------------------------
diff -Naur tk8.5.7.orig/generic/tkColor.c tk8.5.7.new/generic/tkColor.c
--- tk8.5.7.orig/generic/tkColor.c2007-12-13 16:24:13.000000000 +0100
+++ tk8.5.7.new/generic/tkColor.c2009-12-09 12:20:39.000000000 +0100
@@ -302,6 +302,7 @@
      * First, check to see if there's already a mapping for this color name.
      */
 
+    memset(&valueKey, 0, sizeof(valueKey));/* Clear interfield gaps. */
     valueKey.red = colorPtr->red;
     valueKey.green = colorPtr->green;
     valueKey.blue = colorPtr->blue;
User Comments: dkf added on 2009-12-10 05:43:15:

allow_comments - 1