MOO

random() crashes on random(0)

Bug #640379 reported by Goblin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MOO
New
Undecided
Unassigned

Bug Description

I have experienced crashes using the new lambdamoo-1.8.4 code
Using Valgrind, I have narrowed down my search for the bug to bf_random, which appears to have changed a lot since 1.8.2
After replacing the code with an old version of bf_random, the server runs smoothly...

Valgrind output:
==2776== Process terminating with default action of signal 8 (SIGFPE)
==2776== Integer divide by zero at address 0x62D63DB2
==2776== at 0x807CD22: bf_random (in /home/tim/v10/moo)
==2776== by 0x8071D8E: call_bi_func (in /home/tim/v10/moo)
==2776== by 0x8064C7E: run (in /home/tim/v10/moo)
==2776== by 0x806C57B: run_interpreter (in /home/tim/v10/moo)
==2776== by 0x806CB5C: do_server_verb_task (in /home/tim/v10/moo)
==2776== by 0x808D610: run_server_task (in /home/tim/v10/moo)
==2776== by 0x80882D5: main_loop (in /home/tim/v10/moo)
==2776== by 0x8088D52: main (in /home/tim/v10/moo)

-------------------------------------------------

I have narrowed this bug down furthermore and the crash only occurs on random(0).

When looking at the code in bf_random (numbers.c), the fix to this problem is quite obvious...

The line:
    const int range_l = ((INTNUM_MAX > RAND_MAX ? RAND_MAX : (RAND_MAX - num)) + 1) % num;
Should be placed under the if (num <= 0) statement...

Revision history for this message
Goblin (tvd) wrote :

This only applies to the lp:~vcs-imports/moo/test branch... I think I linked it to the whole moo-project now :S

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.