Giter VIP home page Giter VIP logo

Comments (4)

nektro avatar nektro commented on May 30, 2024

update: no allowzero also crashed

from zig.

nektro avatar nektro commented on May 30, 2024

this variation crashes the same way on master but passes on 0.11. the original code snippet also segfaults on 0.11.

const std = @import("std");

test {
    try foo(null);
}

const Color = struct {
    r: u8,
    g: u8,
    b: u8,
    a: u8,
};

fn foo(pixels: ?[]const Color) !void {
    const data: [*]allowzero const u8 = @ptrCast(pixels);
    const int = @intFromPtr(data);
    try std.testing.expect(int == 0);
}

from zig.

garrisonhh avatar garrisonhh commented on May 30, 2024

Here's what I've managed to figure out:

  1. In ptrCastFull, pointer type information about the source and destination types is retrieved through Type.ptrInfo
  2. Type.ptrInfo checks for pointer types wrapped in optional types, and retrieves the underlying InternPool.Key.PtrType
  3. When checking if the source type is a slice and the dest type is a many, C or one pointer, this is done by using the PtrType which does not know whether either type is an option
  4. Finally, analyzeSlicePtr is called and assumes its receiving a slice that isn't optional, resulting in a crash

Working on a PR...

from zig.

garrisonhh avatar garrisonhh commented on May 30, 2024

#18981

from zig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.