www.delorie.com/djgpp/bugs/show.cgi | search |
here is my code: // If you run this repeatedly you will find at least once that the string // Prefix_ has a new line character (*Prefix == '\n') but the strcspn function // won't detect it. In which case ", Pf=1,S=0,n" would be printed indicating the // error. The output indicates that the Prefix_ string was non-null, // the if statement is evaluated to false and there is a '\n' as a first // character of Prefix_ void InsertTabs(const char* Prefix_) { cout <<", Pf=" <<(Prefix_ ? "1":"0"); if (Prefix_ && Prefix_[strcspn(Prefix_, "\n")]) { cout <<".S=1"; // some function calls etc... ) else { cout <<",S=0"; cout <<(*Prefix_ == '\n' ? "n":"x"); } }
I cannot reproduce this problem. I've written a test program for strcspn (it's now part of the test suite, see tests/libc/ansi/string/strcspn.c in djtst203.zip) and ran it on many hundreds of text files: it didn't report even a single failure. I can only assume that the original problem was due to some cockpit error, in the code that was not shown in the above report. For example, the code could overwrite the stack or something. I tried to contact the person who submitted the bug report, but didn't get any replies. I'm closing this report.
webmaster | delorie software privacy |
Copyright © 2010 by DJ Delorie | Updated Jul 2010 |