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

fix Issue 15672 - Casting from void[] to T[] is erroneously considere… #5876

Merged
merged 1 commit into from
Jun 27, 2016

Conversation

WalterBright
Copy link
Member

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
15672 Casting from void[] to T[] is erroneously considered @safe

@WalterBright WalterBright force-pushed the fix15672 branch 2 times, most recently from fc907f8 to f3e50be Compare June 19, 2016 05:56
@PetarKirov
Copy link
Member

LGTM

BTW, with all those @safe fixes, does the spec need to be updated, or you're just fixing the compiler to follow the spec more closely? Anyway it would be helpful if you put @safe label on such PRs for future reference.

@WalterBright
Copy link
Member Author

Blocked by dlang/phobos#4438

@WalterBright
Copy link
Member Author

When all the safety fixed are in, I'll review the spec and make sure it is congruent.

@andralex
Copy link
Member

Actually this is excessive. Casting from void[] to T[] is @safe so long as T has no indirections. Size and alignment are checked dynamically anyway, and if T has no indirections scrambled data won't cause unsafe behavior.

@WalterBright
Copy link
Member Author

Casting from void[] to T[] is @safe so long as T has no indirections

Surprisingly, it is not, as the bugzilla issue shows. The problem comes from an array of pointers being cast to void[], then the void[] is cast to int[], then ints are stored there, then the original array of pointers now has arbitrary pointers in it.

@andralex
Copy link
Member

blurgh thx

@andralex
Copy link
Member

Auto-merge toggled on

@andralex andralex merged commit 5ca4b33 into dlang:master Jun 27, 2016
@WalterBright WalterBright deleted the fix15672 branch June 27, 2016 01:59
PetarKirov added a commit to PetarKirov/D-YAML that referenced this pull request Nov 4, 2016
The following DMD PRs added more rigorous safety checks directly
affecting this project:
* dlang/dmd#5852 (fix Issue 15399 - unaligned pointers are not
  `@safe`) - triggered at line:
  https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/emitter.d#L1011

* dlang/dmd#5940 (Unions may break immutability / unions with
  pointers are un-`@safe` ) - triggered at line:
  https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/event.d#L230

* dlang/dmd#5876 (Casting from `void[]` to `T[]` is erroneously
  considered `@safe`) - triggered at line:
  https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/loader.d#L186

* dlang/dmd#5860 (array.ptr in @safe code may point past end
  of array) - triggered at line:
  https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/zerostring.d#L35
PetarKirov added a commit to PetarKirov/D-YAML that referenced this pull request Nov 4, 2016
The following DMD PRs added more rigorous safety checks directly
affecting this project:
* dlang/dmd#5852 (fix Issue 15399 - unaligned pointers are not
  `@safe`) - triggered at line:
  https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/emitter.d#L1011

* dlang/dmd#5940 (Unions may break immutability / unions with
  pointers are un-`@safe` ) - triggered at line:
  https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/event.d#L230

* dlang/dmd#5876 (Casting from `void[]` to `T[]` is erroneously
  considered `@safe`) - triggered at line:
  https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/loader.d#L186

* dlang/dmd#5860 (array.ptr in @safe code may point past end
  of array) - triggered at line:
  https://github.com/kiith-sa/D-YAML/blob/v0.5.3/source/dyaml/zerostring.d#L35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants