Skip to content

Commit

Permalink
coverity: Use a better random number generator for goom.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Sep 3, 2020
1 parent 6f1c2fc commit c44aa18
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
12 changes: 9 additions & 3 deletions mythtv/libs/libmythtv/visualisations/goom/goom_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <random>

#include "goom_core.h"
#include "goom_tools.h"
Expand Down Expand Up @@ -87,9 +88,7 @@ void goom_init (guint32 resx, guint32 resy, int cinemascope) {
srand ((uintptr_t) pixel);
if (!rand_tab) rand_tab = (int *) malloc (NB_RAND * sizeof(int)) ;
rand_pos = 1 ;
// Pseudo-random is good enough. Don't need a true random.
// NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
while (rand_pos != 0) rand_tab [rand_pos++] = rand () ;
while (rand_pos != 0) rand_tab [rand_pos++] = goom_rand () ;

cycle = 0;

Expand Down Expand Up @@ -978,3 +977,10 @@ void update_message (char *message) {
}
}
*/

guint32 goom_rand (void)
{
static std::random_device rd;
static std::mt19937 mt(rd());
return mt();
}
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/visualisations/goom/goom_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ MTV_PUBLIC void goom_set_resolution (guint32 resx, guint32 resy, int cinemascope
*/
MTV_PUBLIC guint32 *goom_update (GoomDualData& data, int forceMode);
MTV_PUBLIC void goom_close (void);
MTV_PUBLIC guint32 goom_rand (void);

#endif // GOOMCORE_H
5 changes: 2 additions & 3 deletions mythtv/libs/libmythtv/visualisations/goom/ifs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <cstdlib>

#include "ifs.h"
#include "goom_core.h"

#define MODE_ifs

Expand Down Expand Up @@ -279,9 +280,7 @@ init_ifs (int width, int height)
Fractal->m_count = 0;
Fractal->m_lx = (Fractal->m_width - 1) / 2;
Fractal->m_ly = (Fractal->m_height - 1) / 2;
// Pseudo-random is good enough. Don't need a true random.
// NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
Fractal->m_col = rand () % (width * height); /* modif by JeKo */
Fractal->m_col = goom_rand () % (width * height); /* modif by JeKo */

Random_Simis (Fractal, Fractal->m_components, 0, 5 * MAX_SIMI);

Expand Down
10 changes: 3 additions & 7 deletions mythtv/libs/libmythtv/visualisations/goom/tentacle3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ void tentacle_new (void) {
vals = (float*)malloc ((definitionx+20)*sizeof(float));

for (auto & tmp : grille) {
// Pseudo-random is good enough. Don't need a true random.
// NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
int z = 45+rand()%30;
// NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
int x = 85+rand()%5;
int z = 45+goom_rand()%30;
int x = 85+goom_rand()%5;
center.z = z;
// NOLINTNEXTLINE(cert-msc30-c,cert-msc50-cpp)
tmp = grid3d_new (x,definitionx,z,definitionz+rand()%10,center);
tmp = grid3d_new (x,definitionx,z,definitionz+goom_rand()%10,center);
center.y += 8;
}
}
Expand Down

0 comments on commit c44aa18

Please sign in to comment.