View Issue Details

IDProjectCategoryView StatusLast Update
00019371003.1(2024)/Issue8System Interfacespublic2025-08-14 15:19
Reporterdalias Assigned To 
PrioritynormalSeverityEditorialTypeError
Status ResolvedResolutionAccepted As Marked 
NameRich Felker
Organizationmusl libc
User Reference
Sectiontsearch
Page Numberunknown
Line Numberunknown
Interp Status---
Final Accepted Text0001937:0007231
Summary0001937: Undefined behavior in tsearch EXAMPLES text
DescriptionThe usage examples for the tsearch.h interfaces contain multiple expressions of the form:

*(struct element **)node

This accesses the object pointed-to by node with a type (struct element *) not matching its effective type (void *, aka posix_tnode), thereby having undefined behavior.

The intent is to load the value pointed to by node, and interpret it as a pointer to struct element. This can be done correctly as:

(struct element *)*node

This accesses the pointed-to object with the correct type (posix_tnode), then converts the accessed value, rather than trying to access an object with the wrong type.
Desired ActionReplace all 4 instances of:

*(struct element **)

in EXAMPLES with:

(struct element *)*
Tagstc1-2024

Activities

dalias

2025-07-21 16:04

reporter   bugnote:0007225

Oops, it looks like I accidentally filed this for issue 7. Can it be moved to issue 8 (since it's worded relative to issue 8 and still relevant) or should I re-file for issue 8?

dalias

2025-07-21 22:48

reporter   bugnote:0007226

And I was mistakenly thinking posix_tnode was defined as void *, but since it's defined as void, the correct form should be:

 (struct element *)*(void **)

geoffclare

2025-07-22 10:01

manager   bugnote:0007227

The fourth use is not quite the same as it involves const. Given
const posix_tnode *ptr
is this right:
const struct element *p = (const struct element *)*(void **) ptr;
or should there be a const somewhere in the (void **) as well?

geoffclare

2025-07-24 16:42

manager   bugnote:0007231

Last edited: 2025-08-14 15:18

Replace the 1st (line 73286) and 3rd (line 73295) instances of:
*(struct element **)

in EXAMPLES with:
*(void **)


Line 73288 Replace the instance of:
(*(struct element **)node)->count++;

with:
((struct element *)*(void **)node)->count++;

    
Line 73321 Replace the instance of:
const struct element *p = *(const struct element **) ptr;

with:
const struct element *p = *(void **) ptr;

Issue History

Date Modified Username Field Change
2025-07-21 16:02 dalias New Issue
2025-07-21 16:04 dalias Note Added: 0007225
2025-07-21 22:48 dalias Note Added: 0007226
2025-07-22 09:26 geoffclare Project 1003.1(2016/18)/Issue7+TC2 => 1003.1(2024)/Issue8
2025-07-22 10:01 geoffclare Note Added: 0007227
2025-07-24 16:42 geoffclare Note Added: 0007231
2025-08-14 15:18 geoffclare Note Edited: 0007231
2025-08-14 15:19 geoffclare Status New => Resolved
2025-08-14 15:19 geoffclare Resolution Open => Accepted As Marked
2025-08-14 15:19 geoffclare Interp Status => ---
2025-08-14 15:19 geoffclare Final Accepted Text => 0001937:0007231
2025-08-14 15:19 geoffclare Tag Attached: tc1-2024