php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57831 wrong storage class for variable in C functions gscgn() and gssst()
Submitted: 2007-09-11 08:46 UTC Modified: 2016-05-28 05:21 UTC
From: hans at origin dot edvz dot uni-linz dot ac dot at Assigned: uchiyama (profile)
Status: Closed Package: stats (PECL)
PHP Version: 4.4.5 OS: Linux
Private report: No CVE-ID: None
 [2007-09-11 08:46 UTC] hans at origin dot edvz dot uni-linz dot ac dot at
Description:
------------
[Please Note: this is a follow up to bug report
   http://pecl.php.net/bugs/bug.php?id=12011
   --> states already wrong storage class for 
       variable in gsrgs()
]

In randlib.c some variables declared as local to
the function (automatic storage class) need to be
declared with 'static' storage class ... otherwise the
values assigned get lost after return from function.

The random number generator functions won't be usable
at all (-> without fix to gsrgs()) or will yield
ONE value only (i.e. you get always the *SAME* random value).

These are the recommended patches/fixes to the C source file stats-1.0.2/randlib.c

1.  function gscgn(long getset, long *g)
  //MeJ original: long curntg = 1;
  static long curntg = 1; /* MeJ add static storage class  otherwise settings get lost after return from function */

[ reported in bug id=12011
  2.  function  gsrgs(long getset,long *qvalue)
  /*MeJ    original: long qinit = 0;  */
  /*MeJ add static ... otherwise the settings get lost */
  static long qinit = 0;
]

3. function gssst(long getset,long *qset)
  //MeJ original: long qstate = 0;
  static long qstate = 0; /* MeJ add static storage class otherwise settings get lost after return from function */



Reproduce code:
---------------
<? echo " === testing random generator \n";
$low = 0.6;
$high = 2.1;
echo " stats_rand_gen_funiform($low, $high) " . stats_rand_gen_funiform( 0.6, 2.1 ) . "\n";
echo " stats_rand_gen_funiform($low, $high) " . stats_rand_gen_funiform( 0.6, 2.1 ) . "\n";
echo " stats_rand_gen_funiform($low, $high) " . stats_rand_gen_funiform( 0.6, 2.1 ) . "\n";

?>


Expected result:
----------------
rapax DIST/STATS-Extension> /opt/php4/inst/bin/php MeJ-test-rand_gen_funiform.php
X-Powered-By: PHP/4.4.5
Content-type: text/html

 === testing random generator
 stats_rand_gen_funiform(0.6, 2.1) 1.0855658054352
 stats_rand_gen_funiform(0.6, 2.1) 1.0865880250931
 stats_rand_gen_funiform(0.6, 2.1) 1.3400814533234


Actual result:
--------------
rapax DIST/STATS-Extension> /opt/php4/inst/bin/php MeJ-test-rand_gen_funiform.php
X-Powered-By: PHP/4.4.5
Content-type: text/html

 === testing random generator
 stats_rand_gen_funiform(0.6, 2.1) 1.0855658054352
 stats_rand_gen_funiform(0.6, 2.1) 1.0855658054352
 stats_rand_gen_funiform(0.6, 2.1) 1.0855658054352

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-17 01:39 UTC] wendellp at operamail dot com
This seems to have been fixed in v1.0.3.
 [2016-05-28 00:24 UTC] uchiyama@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: uchiyama
 [2016-05-28 05:21 UTC] uchiyama@php.net
-Status: Assigned +Status: Closed
 [2016-05-28 05:21 UTC] uchiyama@php.net
Fixed in version 1.0.4/2.0.2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC