[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#185242: Error in testcase program.



As Philip Martin pointed out in bug 185242, the testcase program 
submitted is incorrect; having failed to return rval, the return value 
is undefined in the case that rval != max.

Fixing this problem, I am unable to reproduce the bug on gcc-3.2 (though 
still on gcc-3.0). New source code appears below:

#include <ext/rope>
#include <iostream>
#include <assert.h>

using namespace std;
using namespace __gnu_cxx;

static unsigned int rand(unsigned int max) {
  unsigned int rval = (unsigned int)(((double)max)*rand()/(RAND_MAX));
  if (rval == max)
    return max-1;
  return rval;
}

int main() {
  crope r;
  char buf[10240];
  
  while (1) {
    if (rand(2) && r.size() < 1024*1024) {
      unsigned int s = rand(10240);
      assert(s <= 10240);
      r.append(buf, rand(10240));
    } else if (r.size() > 10240) {
      unsigned int s = rand(10240);
      assert(s <= r.size());
      r.erase(0, rand(10240));
    }
  }
  return 0;
}




Reply to: