Skip to content

fix: to_num_from_stream pointer position correction #1000

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

Merged
merged 1 commit into from
Jun 9, 2025

Conversation

jalvesz
Copy link
Contributor

@jalvesz jalvesz commented Jun 8, 2025

This PR fixes the computation of the position in a character stream for the to_num_from_stream function to properly advance when the character is a long chain. Otherwise, negative numbers can be obtained from len(s, lind=int8) if the string is in effect larger than 127.

@@ -109,7 +109,7 @@ module stdlib_str2num
integer(int8) :: err
!----------------------------------------------
call to_num_base(s,v,p,err)
p = min( p , len(s, kind = int8) )
p = min( p , len(s) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As p is declared as integer(int8), similar issues might still happen. Maybe also declare p as integer :: p? Or do you think it is not needed?

Copy link
Contributor Author

@jalvesz jalvesz Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not needed as the kind is converted as an output of min. It could happen if an individual number is written on more than 127 characters. But even a quad number would fit.

Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jalvesz . LGTM. See my suggestion below.

@jalvesz jalvesz merged commit 25f94a9 into fortran-lang:master Jun 9, 2025
16 checks passed
github-actions bot added a commit to banana-bred/stdlib that referenced this pull request Jun 9, 2025
github-actions bot added a commit to banana-bred/stdlib that referenced this pull request Jun 9, 2025
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

Successfully merging this pull request may close these issues.

3 participants