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

[CN] crash if array size expression evaluates to a negative number #777

Open
peterohanley opened this issue Dec 20, 2024 · 0 comments
Open
Labels
bug Something isn't working cn

Comments

@peterohanley
Copy link

failing cases (array size evaluates to -1)

struct a {
  int b[sizeof(char) - 2];
};
cn: internal error, uncaught exception:
    Z.Overflow
    Raised by primitive operation at Z.to_int in file "z.ml", line 221, characters 46-56
    Called from Cn__Core_to_mucore.make_struct_decl in file "backend/cn/lib/core_to_mucore.ml", line 1457, characters 23-56
    Called from Cn__Core_to_mucore.normalise_tag_definition in file "backend/cn/lib/core_to_mucore.ml", line 1493, characters 53-86
    Called from Cn__Core_to_mucore.normalise_tag_definitions.(fun) in file "backend/cn/lib/core_to_mucore.ml", line 1501, characters 20-52
    Called from Pmap.fold in file "pmap.ml", line 156, characters 15-38
    Called from Cn__Core_to_mucore.normalise_file in file "backend/cn/lib/core_to_mucore.ml", line 1526, characters 17-58
    ...
int b[sizeof(char) - 2];
cn: internal error, uncaught exception:
    Failure("int_of_big_int")
    Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33
    Called from Cerb_frontend__Cabs_to_ail_aux.mk_zeroInit_aux in file "ocaml_frontend/generated/cabs_to_ail_aux.ml", line 128, characters 34-56
    Called from Cerb_frontend__Cabs_to_ail_aux.mk_zeroInit in file "ocaml_frontend/generated/cabs_to_ail_aux.ml", line 161, characters 17-47
    Called from Cerb_frontend__Cabs_to_ail_effect.extract_program.(fun) in file "ocaml_frontend/generated/cabs_to_ail_effect.ml", line 2702, characters 51-86
    Called from Cerb_frontend__State_exception.stExpect_bind in file "ocaml_frontend/generated/state_exception.ml", line 19, characters 24-29
    ....

normal cases (array size evaluates to 0)

struct a {
  int b[sizeof(char) - 1];
};
pre.c:2:7: error: constraint violation: array declared with a negative or zero size
  int b[sizeof(char) - 1];
      ^~~~~~~~~~~~~~~~~~~~ 

The error is the same if the array is not inside a struct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cn
Projects
None yet
Development

No branches or pull requests

2 participants