[swift-dev] quick, spot the UB in this code:

Daniel Dunbar daniel_dunbar at apple.com
Thu Apr 7 00:00:54 CDT 2016


> On Apr 6, 2016, at 9:58 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> 
> On Wed, Apr 6, 2016 at 9:54 PM, Daniel Dunbar <daniel_dunbar at apple.com> wrote:
>> Could we get a method that takes a [UInt8] directly and performs the same basic function?
> 
> I think the root of the surprise here is that the compiler converts
> [UInt8] into an unsafe pointer.  This is appropriate when the callee
> is a C API, but usually not appropriate when it is a Swift API.  This
> is not the first time when this implicit conversion causes surprise.
> I think we should discuss scoping that conversion to only C and
> Objective-C calls.

+1 from me.

> But I agree with you, we should have a similar operation that works on
> arbitrary collections.

Cool, thanks.

 - Daniel

> 
> Dmitri
> 
> -- 
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/



More information about the swift-dev mailing list