8000 fix overflow n_reads in show_progress_until_done by telmin · Pull Request #265 · ksahlin/strobealign · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix overflow n_reads in show_progress_until_done #265

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 3 commits into from
Apr 24, 2023

Conversation

telmin
Copy link
Contributor
@telmin telmin commented Apr 24, 2023

Hi.
I was running Strobealign on a large file and noticed that it overflows when the number of reads exceeds the int limit.
n_reads are type inferred as signed int, but here it is better to use size_t.
I fixed this and would appreciate it if you could merge it.

@marcelm
Copy link
Collaborator
marcelm commented Apr 24, 2023

Oh, good point! I’d be happy to merge this as-is, but would you perhaps be interested in fixing AlignmentStatistics as well? The unsigned ints there (n_reads, tot_aligner_calls etc.) should probably be uint64_t.

@telmin
Copy link
Contributor Author
telmin commented Apr 24, 2023

Thank you for your comment.
You're right, it would be better it is unsigned int to size_t there too! I will change it.

@telmin
Copy link
Contributor Author
telmin commented Apr 24, 2023

Changes have been made and corrections made where necessary. Could you please review it?

src/aln.hpp Outdated
unsigned int tot_all_tried = 0;
unsigned int did_not_fit = 0;
unsigned int tried_rescue = 0;
size_t n_reads = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don’t think size_t is the appropriate type here. It is used to represent the size of an object, so it’s used for array indices etc. While it works here because size_t happens to be an unsigned long on the platforms we care about, size_t it is only required to be at least 16 bits, so it could overflow on another platform. I would prefer using a type that does not depend on the platform, so in this case an uint64_t.

The strobealign code is not very consistent, yet, in using these explicitly-sized types, sorry for the confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review.
You are indeed correct. I have fix it.

@marcelm
Copy link
Collaborator
marcelm commented Apr 24, 2023

Thanks! I’m sure this is fine with @ksahlin, so I’ll merge this now.

@marcelm marcelm merged commit 7641106 into ksahlin:main Apr 24, 2023
@telmin telmin deleted the fix_overflow_in_progress_func branch April 24, 2023 17:22
rebjannik pushed a commit to rebjannik/strobealign that referenced this pull request May 17, 2025
fix overflow n_reads in show_progress_until_done
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.

2 participants
0