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

c2hs crashes on invalid input #180

Closed
kolmodin opened this issue Jan 21, 2017 · 0 comments
Closed

c2hs crashes on invalid input #180

kolmodin opened this issue Jan 21, 2017 · 0 comments

Comments

@kolmodin
Copy link
Member

I had written this c2hs code;

-- | Validate the key of a metadata pair.
{#fun pure grpc_header_key_is_legal as isKeyValid
  { 'useAsCStringLen'* `B.ByteString'&} -> `Bool' #}

But the C code had been updated from char*, size_t to grpc_slice;

GRPCAPI int grpc_header_key_is_legal(grpc_slice slice);

Thus c2hs expects two arguments in the C function, but there was only one.
Naturally c2hs needs to fail generating the bindings, but the failure should be informative.

Currently it crashes at runtime with an error message which doesn't tell you where in your code you have a problem;

c2hs: src/C2HS/Gen/Bind.hs:(1426,5)-(1444,66): Non-exhaustive patterns in function addDft

Turning the incomplete patterns warnings in c2hs back on;

src/C2HS/Gen/Bind.hs:1426:5: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘addDft’:
        Patterns not matched:
            (CHSPlusParm _:_) []
            (CHSParm _ _ True _ _ _ _:_) [_]

I also filed a bug to fix the incomplete patterns; #179.

kolmodin added a commit to kolmodin/c2hs that referenced this issue Jan 21, 2017
kolmodin added a commit to kolmodin/c2hs that referenced this issue Jan 21, 2017
kolmodin added a commit to kolmodin/c2hs that referenced this issue Feb 2, 2017
kolmodin added a commit to kolmodin/c2hs that referenced this issue Feb 2, 2017
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

No branches or pull requests

1 participant