Sitelet https://web.archive.org/web/20200825030216/https://github.com/rapidsai/cudf/issues/6029
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] reinterpret_cast is misused in many places in cuIO #6029

Open
vuule opened this issue Aug 18, 2020 · 0 comments
Open

[BUG] reinterpret_cast is misused in many places in cuIO #6029

vuule opened this issue Aug 18, 2020 · 0 comments

Comments

@vuule
Copy link
Collaborator

@vuule vuule commented Aug 18, 2020

There are (at least) two ways in which the reinterpret_cast is misused:

  1. Used instead of static_cast:
    dataptr = reinterpret_cast<uint8_t *>(schema[i].dataptr);

    static cast should be used to cast from void*.
  2. The use causes undefined behavior:
    reinterpret_cast<int32_t *>(dataptr)[row] = static_cast<int32_t>(v);

    reinterpret_cast<nvstrdesc_s *>(dataptr)[row].ptr = ptr;
    reinterpret_cast<nvstrdesc_s *>(dataptr)[row].count = count;

    These uses break the type aliasing rules as they cast between pointers to types that are not similar.

Proposed solution:

  • Use static_cast where appropriate.
  • Buffers whose data type is not known at compile time (input/output buffers usually) should be of type void* instead of uint8_t*, as they commonly are now.
    • Addition of a hostdevice_buffer type might be beneficial here.
  • Where the options above are not applicable, use std::memcpy instead of the cast.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.