Skip to content

_const_cast is de facto undefined behavior #6980

@badasahog

Description

@badasahog

data.table/src/fread.c

Lines 126 to 133 in 9c54bd0

/**
* Drops `const` qualifier from a `const char*` variable, equivalent of
* `const_cast<char*>` in C++.
*/
static char* _const_cast(const char *ptr) {
union { const char *a; char *b; } tmp = { ptr };
return tmp.b;
}

I am aware that the usage of sidestepping constness is used to invoke copy on write behavior.

This is still undefined behavior.

I'm going to investigate to see if I can find a decent solution to this problem, and I also want to hear back if anyone disagrees with my assessment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions