Skip to content

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

Merged
andralex merged 1 commit intodlang:masterfrom
WalterBright:fix15672
Jun 27, 2016
Merged

fix Issue 15672 - Casting from void[] to T[] is erroneously considere…#5876
andralex merged 1 commit intodlang:masterfrom
WalterBright:fix15672

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

Development

Successfully merging this pull request may close these issues.

4 participants