Nothing Special   »   [go: up one dir, main page]

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

The Ocaml printer crashes if the indent level becomes negative #439

Closed
Arm-Mike opened this issue Mar 3, 2023 · 1 comment · Fixed by #440
Closed

The Ocaml printer crashes if the indent level becomes negative #439

Arm-Mike opened this issue Mar 3, 2023 · 1 comment · Fixed by #440
Assignees
Labels
OCaml printer Concerning the generated printer
Milestone

Comments

@Arm-Mike
Copy link
Arm-Mike commented Mar 3, 2023

The follow type of rule causes the ocaml printer to crash
test. A ::= "{{" Id "}" "}" ; -- Note: should be "}}"

The error message is Fatal error: exception Invalid_argument("Bytes.create")

I have traced this to the indent function let indent (i: int) : string = "\n" ^ String.make i ' ' and I think that changed to let indent (i: int) : string = if i > 0 then "\n" ^ String.make i ' ' else "\n" ;; to match the behavior of other backends.

@andreasabel andreasabel added this to the 2.9.5 milestone Mar 4, 2023
@andreasabel andreasabel added OCaml printer Concerning the generated printer labels Mar 4, 2023
@andreasabel andreasabel self-assigned this Mar 4, 2023
@andreasabel
Copy link
Member

@Arm-Mike : Good catch, thanks for the report!

Maybe it is a bit silly by Ocaml to not truncate negative quantities passed to String.make. They seem to be obsessed with not a bounds check too much, living by the motto let it crash.

Anyway, I fixed this along the lines you suggested, and the fix should be on master soon. Is this fine with you or do you need a release of this fix urgently?

As a workaround, you can always patch the output of BNFC with the patch commandline tool.

andreasabel added a commit that referenced this issue Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCaml printer Concerning the generated printer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants