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

Bug: read() gives invalid output #4015

Closed
kmr-srbh opened this issue May 17, 2024 · 4 comments · Fixed by #4021
Closed

Bug: read() gives invalid output #4015

kmr-srbh opened this issue May 17, 2024 · 4 comments · Fixed by #4021
Labels
bug Something isn't working easy to fix Easy to fix issue (good first issue for a new contributor) good first issue Good for newcomers

Comments

@kmr-srbh
Copy link
Contributor

This bug was caught when working on #4011.

b.f90

program main
    character :: c
    open(11, file="intrinsics_60_data.txt", form="formatted", access="stream", status="old")
    read(11, *) c
    print *, c
    print*, len(c)
end
$ gfortran b.f90 && ./a.out
 H
           1
$ lfortran b.f90 --no-warnings
Hello
5

intrinsics_60_data.txt

Hello

When ready with a fix, please also verify the integration test intrinsics_60.f90.

@kmr-srbh kmr-srbh added the bug Something isn't working label May 17, 2024
@gxyd
Copy link
Contributor

gxyd commented May 17, 2024

Seems like _lfortran_read_char doesn't take into account the length of the passes character string to it. Probably needs another argument for it. The same issue currently happens for when the input is taken from the console:

program main
    character(len=2) :: c
    read *, c
    print *, c
    print*, len(c)
end

if we enter "apple" as the string from console. It will output:

apple
5

instead of the correct output:

ap
2

Same issue happens for when, padding of spaces needs to be done.

@kmr-srbh
Copy link
Contributor Author

@gxyd thanks for the finding! This should be easy to fix I think. 👍

@kmr-srbh kmr-srbh added good first issue Good for newcomers easy to fix Easy to fix issue (good first issue for a new contributor) labels May 17, 2024
@kmr-srbh
Copy link
Contributor Author

kmr-srbh commented May 17, 2024

@gxyd are you working on this? I have a fix ready for this.

@gxyd
Copy link
Contributor

gxyd commented May 17, 2024

I was going to submit a fix just now, but I'm happy to work on this together so that either of our solution can be merged. So, submit a PR for it, and I'll review that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working easy to fix Easy to fix issue (good first issue for a new contributor) good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants