0

Twice now my server has crashed after several days of running on this line.

int randomValue = rand() % m_list.size();

where m_list is

std::list<int> m_list;

The crash is

Program terminated with signal 8, Arithmetic exception.

getting the size of a list should be guaranteed to not be negative. What could cause this crash? Can something with rand be the cause? I seed rand at the start of my server with

srand(time(NULL));

Any tips are appreciated!

Josh Brittain
  • 2,162
  • 7
  • 31
  • 54

1 Answers1

3

I don't have that much information about the situation, but does the list have anything in it? If not, you'd be dividing by zero, and that would explain everything.

So, first step is to make sure that m_list is not zero.

If it is, perhaps you could check to make sure that the size of the list is not zero before performing the operation.

Klompengard
  • 304
  • 2
  • 12
  • Welp, I feel silly. I don't know why I didn't think about that. That is definitely the problem, thanks guys! I will accept answer as soon as I can. – Josh Brittain May 23 '14 at 22:29