86 - [SFL] 'random(num)' macro is wrong in sfl.h

Reported by fjardonfjardon (1270027409|%O ago)

testfind.c crashes with segmentation fault. This is due to the 'random(num)' macro in sfl.h.

The macro is defined as:

  1. define random(num) (int) ((float) num * rand () / (RAND_MAX + 1.0))

It should be:

  1. define random(num) (int) ((float) (num) * rand () / (RAND_MAX + 1.0))

The crash is caused by the following lines in testfind.c:
fill_random (byte *block, int minimum, int maximum)
{
…..

block_size = minimum + random (maximum-minimum) + 1;
…..
}

Where the block size is computed as: minimum + (maximum - minimum*rand()/RAND_MAX), which is ALWAYS greater then maximum….

—- sfl.h 2009-05-23 19:11:14.000000000 +0200

../libsfl-3.31-patched/sfl.h 2010-03-31 11:16:50.000000000 +0200

-470,7 +470,7
#define tbllast(x) (x [tblsize (x) - 1])

#if (!defined (random))
-# define random(num) (int) ((float) num * rand () / (RAND_MAX + 1.0))
+# define random(num) (int) ((float) (num) * rand () / (RAND_MAX + 1.0))
# define randomize() srand ((unsigned) time (NULL))
#endif
#if (!defined (min))

—- prelude.h 2009-05-23 18:57:08.000000000 +0200

../libsfl-3.31-patched/prelude.h 2010-03-31 11:16:34.000000000 +0200

-430,7 +430,7
#define tbllast(x) (x [tblsize (x) - 1])

#if (!defined (random))
-# define random(num) (int) ((float) num * rand () / (RAND_MAX + 1.0))
+# define random(num) (int) ((float) (num) * rand () / (RAND_MAX + 1.0))
# define randomize() srand ((unsigned) time (NULL))
#endif
#if (!defined (min))

Attachments:

No files attached to this page.

Comments

Add a New Comment

Edit | Files | Tags | Print

rating: 0+x

Who's following this issue?

pieterhpieterh
martin_sustrikmartin_sustrik
CybariteCybarite
fjardonfjardon
Watch: site | category | page

Submitted by fjardonfjardon

Use one of these tags to say what kind of issue it is:

  • issue - a fault in the software or the packaging or the documentation.
  • change - a change or feature request.

Use one of these tags to say what state the issue is in:

  • open - a new, open issue.
  • closed - issue has been closed.
  • rejected - the issue has been rejected.

Use one of these tags to say how urgent the issue is:

  • fatal - the issue is stopping all work.
  • urgent - it's urgent.

All open

Most recent

Page tags: open