| Ticket UUID: | b2de5886c686a6ea82373efa7f3cc687eb3015c0 | |||
| Title: | Misleading comment in tkImgPhInstance.c | |||
| Type: | Bug | Version: | all | |
| Submitter: | chrstphrchvz | Created on: | 2026-10-14 04:49:50 | |
| Subsystem: | 41. Photo Images | Assigned To: | jan.nijtmans | |
| Priority: | 5 Medium | Severity: | Cosmetic | |
| Status: | Closed | Last Modified: | 2026-10-18 08:45:53 | |
| Resolution: | Fixed | Closed By: | jan.nijtmans | |
| Closed on: | 2026-10-18 08:45:53 | |||
| Description: |
In
I suggest removing or at least rewording this comment. The C standard does not require compilers to copy padding during struct assignment. Unless HP, etc. documented that their compilers would copy such padding (which I doubt they did), there were never any such compiler bugs. | |||
| User Comments: |
jan.nijtmans added on 2026-10-18 08:45:53:
Now fixed in [01c4ab26997c6d61|trunk], core-9-0-branch and core-8-6-branch. > Replacing the second `memset()` call and assignment with `memcpy()` as Jan proposed does seem better Thanks! chrstphrchvz added on 2026-10-17 07:07:24: The comment also has a typo: it meant to say I am trying to understand exactly what prompted Marc's comment. Here is the relevant excerpt from tk4.0p1.patch (the first post-release bugfix patch to Tk 4.0), if it helps provide context:
Both the comment (whose author expected ยง6.2.6.1 of the C standard has said:
The part in parentheses is what prompted this ticket. But now I also think this paragraph means that after assigning to all members of marc_culler (claiming to be Marc Culler) added on 2026-10-16 21:07:55: I really don't believe that allocating N bytes and using memset to set those N bytes to 0 could possibly fail to clear all of the allocated memory. I don't see how memset could possibly know anything about what sort of struct is going to eventually be copied into the newly allocated block of memory. And I don't believe that sizeof would ever fail to account for any padding needed for alignment. I think that doing the straightforward thing and removing the comment would work fine. Since there is no allocation function like calloc provided by Tcl, I think allocating the memory and clearing it with memset is a perfectly standard thing to do, and I also see that it is done throughout the generic Tk code. jan.nijtmans added on 2026-10-15 10:09:54: Thinking more on it, [3939c8d2f32d6ccc|this] is better. In stead of initializing the whole (large) struct, just use memcpy() to make sure the (eventual) padding bits are copied as well. On modern systems, there will be padding between `gamma` and `palette`, we - indeed - have to make sure those padding bytes are initialized. jan.nijtmans added on 2026-10-15 10:02:22: How about [47acbe2ae9|this]? I agree that the described behavior is no bug. When using a struct as hash key, we need to assure that all bytes are initialized. Therefore, I propose to initialize all of the ColorTable in a single `memset`, and just initialize the two fields (id and visualInfo). Or would that be too much? | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki