Skip to content

Commit f76a7cc

Browse files
committed
darwin: fix IOKit warnings about const char * being passed in arrays
GCC11 emits warnings [-Wstringop-overread] when passing short C strings in io_name/string_t in the IOKit API because those types are 128/512 char arrays. It's not clear if these warnings are really valid but they are not too hard to fix (we cannot cast into an array type, so just declare a variable of that array type earlier). By the way, update the actual definition of io_name/string_t in our port test headers. Thanks to Ralph Castain for the report. Fixes #599 Signed-off-by: Brice Goglin <[email protected]>
1 parent 49b940c commit f76a7cc

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

hwloc/topology-darwin.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ static void hwloc__darwin_cpukinds_add_cpu(struct hwloc_darwin_cpukinds *kinds,
108108
#define kIOMainPortDefault kIOMasterPortDefault
109109
#endif
110110

111-
#define DT_PLANE "IODeviceTree"
112-
113111
static int hwloc__darwin_look_iokit_cpukinds(struct hwloc_darwin_cpukinds *kinds,
114112
int *matched_perflevels)
115113
{
@@ -118,16 +116,19 @@ static int hwloc__darwin_look_iokit_cpukinds(struct hwloc_darwin_cpukinds *kinds
118116
io_registry_entry_t cpus_child;
119117
kern_return_t kret;
120118
unsigned i;
119+
#define DT_PLANE "IODeviceTree"
120+
io_string_t cpu_plane_string = DT_PLANE ":/cpus";
121+
io_name_t dt_plane_name = DT_PLANE;
121122

122-
hwloc_debug("\nLooking at cpukinds under " DT_PLANE ":/cpus ...\n");
123+
hwloc_debug("\nLooking at cpukinds under %s\n", (const char *) cpu_plane_string);
123124

124-
cpus_root = IORegistryEntryFromPath(kIOMainPortDefault, DT_PLANE ":/cpus");
125+
cpus_root = IORegistryEntryFromPath(kIOMainPortDefault, cpu_plane_string);
125126
if (!cpus_root) {
126-
fprintf(stderr, "hwloc/darwin/cpukinds: failed to find " DT_PLANE ":/cpus\n");
127+
fprintf(stderr, "hwloc/darwin/cpukinds: failed to find %s\n", (const char *) cpu_plane_string);
127128
return -1;
128129
}
129130

130-
kret = IORegistryEntryGetChildIterator(cpus_root, DT_PLANE, &cpus_iter);
131+
kret = IORegistryEntryGetChildIterator(cpus_root, dt_plane_name, &cpus_iter);
131132
if (kret != KERN_SUCCESS) {
132133
if (HWLOC_SHOW_ALL_ERRORS())
133134
fprintf(stderr, "hwloc/darwin/cpukinds: failed to create iterator\n");
@@ -145,7 +146,7 @@ static int hwloc__darwin_look_iokit_cpukinds(struct hwloc_darwin_cpukinds *kinds
145146
{
146147
/* get the name */
147148
io_name_t name;
148-
kret = IORegistryEntryGetNameInPlane(cpus_child, DT_PLANE, name);
149+
kret = IORegistryEntryGetNameInPlane(cpus_child, dt_plane_name, name);
149150
if (kret != KERN_SUCCESS) {
150151
hwloc_debug("failed to find cpu name\n");
151152
} else {
@@ -155,7 +156,7 @@ static int hwloc__darwin_look_iokit_cpukinds(struct hwloc_darwin_cpukinds *kinds
155156
#endif
156157

157158
/* get logical-cpu-id */
158-
ref = IORegistryEntrySearchCFProperty(cpus_child, DT_PLANE, CFSTR("logical-cpu-id"), kCFAllocatorDefault, kNilOptions);
159+
ref = IORegistryEntrySearchCFProperty(cpus_child, dt_plane_name, CFSTR("logical-cpu-id"), kCFAllocatorDefault, kNilOptions);
159160
if (!ref) {
160161
/* this may happen on old/x86 systems that aren't hybrid, don't warn */
161162
hwloc_debug("failed to find logical-cpu-id\n");
@@ -183,7 +184,7 @@ static int hwloc__darwin_look_iokit_cpukinds(struct hwloc_darwin_cpukinds *kinds
183184

184185
#ifdef HWLOC_DEBUG
185186
/* get logical-cluster-id */
186-
ref = IORegistryEntrySearchCFProperty(cpus_child, DT_PLANE, CFSTR("logical-cluster-id"), kCFAllocatorDefault, kNilOptions);
187+
ref = IORegistryEntrySearchCFProperty(cpus_child, dt_plane_name, CFSTR("logical-cluster-id"), kCFAllocatorDefault, kNilOptions);
187188
if (!ref) {
188189
hwloc_debug("failed to find logical-cluster-id\n");
189190
continue;
@@ -207,7 +208,7 @@ static int hwloc__darwin_look_iokit_cpukinds(struct hwloc_darwin_cpukinds *kinds
207208
#endif
208209

209210
/* get cluster-type */
210-
ref = IORegistryEntrySearchCFProperty(cpus_child, DT_PLANE, CFSTR("cluster-type"), kCFAllocatorDefault, kNilOptions);
211+
ref = IORegistryEntrySearchCFProperty(cpus_child, dt_plane_name, CFSTR("cluster-type"), kCFAllocatorDefault, kNilOptions);
211212
if (!ref) {
212213
if (HWLOC_SHOW_ALL_ERRORS())
213214
fprintf(stderr, "hwloc/darwin/cpukinds: failed to find cluster-type\n");
@@ -244,7 +245,7 @@ static int hwloc__darwin_look_iokit_cpukinds(struct hwloc_darwin_cpukinds *kinds
244245
CFRelease(ref);
245246

246247
/* get compatible */
247-
ref = IORegistryEntrySearchCFProperty(cpus_child, DT_PLANE, CFSTR("compatible"), kCFAllocatorDefault, kNilOptions);
248+
ref = IORegistryEntrySearchCFProperty(cpus_child, dt_plane_name, CFSTR("compatible"), kCFAllocatorDefault, kNilOptions);
248249
if (!ref) {
249250
if (HWLOC_SHOW_ALL_ERRORS())
250251
fprintf(stderr, "hwloc/darwin/cpukinds: failed to find compatible\n");

tests/hwloc/ports/include/darwin/IOKit/IOKitLib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
typedef int io_registry_entry_t;
77
typedef int io_iterator_t;
88
typedef int io_object_t;
9-
typedef const char io_name_t[10];
10-
typedef const char * io_string_t;
9+
typedef const char io_name_t[128];
10+
typedef const char io_string_t[512];
1111

1212
typedef int kern_return_t;
1313
#define KERN_SUCCESS 0

0 commit comments

Comments
 (0)