Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address Petr's review
  • Loading branch information
picnixz committed Feb 22, 2025
commit 46ccb79a71b392b705b1ac344294b029ee73af44
13 changes: 6 additions & 7 deletions Modules/pyexpat.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,12 @@ typedef struct {

#define CHARACTER_DATA_BUFFER_SIZE 8192

typedef const void* xmlhandler;
typedef const void *xmlhandler;
typedef void (*xmlhandlersetter)(XML_Parser self, xmlhandler handler);

struct HandlerInfo {
const char *name;
// To avoid UBSan failures, we cannot use the 'xmlhandlersetter' type,
// as the signature of the setters will not be compatible. However, we
// can safely convert the pointers since a setter function will be passed
// a correct handler.
const void *setter;
xmlhandlersetter setter;
xmlhandler handler;
PyGetSetDef getset;
};
Expand Down Expand Up @@ -2215,8 +2211,11 @@ clear_handlers(xmlparseobject *self, int initial)

static struct HandlerInfo handler_info[] = {

// The cast to `xmlhandlersetter` is needed as the signature of XML
// handler functions is not compatible with `xmlhandlersetter` since
// their second parameter is narrower than a `const void *`.
#define HANDLER_INFO(name) \
{#name, XML_Set##name, my_##name},
{#name, (xmlhandlersetter)XML_Set##name, my_##name},

HANDLER_INFO(StartElementHandler)
HANDLER_INFO(EndElementHandler)
Expand Down