Skip to content

Commit 208857e

Browse files
committed
dk_get_index/dk_set_index uses a type indices variable
Issue #27350.
1 parent b6e3634 commit 208857e

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

Objects/dictobject.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,22 @@ dk_get_index(PyDictKeysObject *keys, Py_ssize_t i)
307307
Py_ssize_t ix;
308308

309309
if (s <= 0xff) {
310-
ix = ((char*) &keys->dk_indices[0])[i];
310+
char *indices = (char*)keys->dk_indices;
311+
ix = indices[i];
311312
}
312313
else if (s <= 0xffff) {
313-
ix = ((int16_t*)&keys->dk_indices[0])[i];
314+
int16_t *indices = (int16_t*)keys->dk_indices;
315+
ix = indices[i];
314316
}
315317
#if SIZEOF_VOID_P > 4
316318
else if (s <= 0xffffffff) {
317-
ix = ((int32_t*)&keys->dk_indices[0])[i];
319+
int32_t *indices = (int32_t*)keys->dk_indices;
320+
ix = indices[i];
318321
}
319322
#endif
320323
else {
321-
ix = ((Py_ssize_t*)&keys->dk_indices[0])[i];
324+
Py_ssize_t *indices = (Py_ssize_t*)keys->dk_indices;
325+
ix = indices[i];
322326
}
323327
assert(ix >= DKIX_DUMMY);
324328
return ix;
@@ -333,21 +337,25 @@ dk_set_index(PyDictKeysObject *keys, Py_ssize_t i, Py_ssize_t ix)
333337
assert(ix >= DKIX_DUMMY);
334338

335339
if (s <= 0xff) {
340+
char *indices = (char*)keys->dk_indices;
336341
assert(ix <= 0x7f);
337-
((char*) &keys->dk_indices[0])[i] = (char)ix;
342+
indices[i] = (char)ix;
338343
}
339344
else if (s <= 0xffff) {
345+
int16_t *indices = (int16_t*)keys->dk_indices;
340346
assert(ix <= 0x7fff);
341-
((int16_t*) &keys->dk_indices[0])[i] = (int16_t)ix;
347+
indices[i] = (int16_t)ix;
342348
}
343349
#if SIZEOF_VOID_P > 4
344350
else if (s <= 0xffffffff) {
351+
int32_t *indices = (int32_t*)keys->dk_indices;
345352
assert(ix <= 0x7fffffff);
346-
((int32_t*) &keys->dk_indices[0])[i] = (int32_t)ix;
353+
indices[i] = (int32_t)ix;
347354
}
348355
#endif
349356
else {
350-
((Py_ssize_t*) &keys->dk_indices[0])[i] = ix;
357+
Py_ssize_t *indices = (Py_ssize_t*)keys->dk_indices;
358+
indices[i] = ix;
351359
}
352360
}
353361

0 commit comments

Comments
 (0)