www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000298

When Created: 08/01/1999 23:00:25
Against DJGPP version: 2.02
By whom: haqr@home.com
Abstract: strcspn function fails sometime, not totally reliable
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"); 
  }
}

Note added: 08/15/1999 08:00:51
By whom: eliz@is.elta.co.il
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.

Closed on 08/15/1999 08:00:04: Problem cannot be reproduced.
By whom: eliz@is.elta.co.il



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010