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

Infinite loop when parsing auguments #285

Closed
hasindu2008 opened this issue Nov 30, 2017 · 1 comment
Closed

Infinite loop when parsing auguments #285

hasindu2008 opened this issue Nov 30, 2017 · 1 comment

Comments

@hasindu2008
Copy link
Contributor

When parsing the arguments under each subprogram getopt_long function has been used as follows.

nanopolish_call_methylation.cpp:    for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {
nanopolish_call_variants.cpp:    for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {
nanopolish_extract.cpp:    for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {
nanopolish_getmodel.cpp:    for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {
nanopolish_index.cpp:    for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {
nanopolish_methyltrain.cpp:    for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {
nanopolish_phase_reads.cpp:    for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {
nanopolish_scorereads.cpp:    for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {
nanopolish_train_poremodel_from_basecalls.cpp:    for (char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {

Variable c has been declared as a char and it is compared with -1. In x86 this works fine as char is signed. However, in architectures such as ARM and PowerPC char is unsigned by default and hence it causes an infinite loop.
See : http://www.network-theory.co.uk/docs/gccintro/gccintro_71.html

A simple fix would be to either include -fsigned-char to the compilation flags in makefile or explicitly declaring c as signed char, for instance

nanopolish_call_methylation.cpp:    for (signed char c; (c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1;) {
@jts
Copy link
Owner

jts commented Dec 5, 2017

Thanks for reporting this, I have added -fsigned-char.

@jts jts closed this as completed Dec 5, 2017
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

No branches or pull requests

2 participants