Skip to content

Commit 048581e

Browse files
committed
testcard2/noise: use ug_rand
not much importatnt but rather for the tools (clang-ticy, perhaps also Coverity) not to complain about use of rand() also use (UCHAR_MAX + 1) instead of 256 (for warning fix only)
1 parent ffaeadb commit 048581e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/utils/random.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <[email protected]>
44
*/
55
/*
6-
* Copyright (c) 2023 CESNET, z. s. p. o.
6+
* Copyright (c) 2023-2025 CESNET, zájmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -55,6 +55,8 @@
5555
#include "tv.h"
5656

5757
/**
58+
* Initialize (seed) random engine. Called with common_preinit (host.cpp)>
59+
*
5860
* @note
5961
* Windows rand_s() is not supposed to be seeded
6062
* @remark

src/video_capture/testcard2.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include <assert.h> // for assert
4646
#include <ctype.h> // for isdigit
4747
#include <errno.h> // for errno
48-
#include <limits.h> // for SHRT_MAX
48+
#include <limits.h> // for SHRT_MAX, UCHAR_MAX
4949
#include <math.h> // for sin, M_PI
5050
#include <pthread.h> // for pthread_mutex_lock, pthread_m...
5151
#include <stdbool.h> // for false, true, bool
@@ -76,6 +76,7 @@
7676
#include "utils/color_out.h" // for color_printf, TBOLD, TRED
7777
#include "utils/fs.h" // for MAX_PATH_SIZE
7878
#include "utils/macros.h" // for IS_KEY_PREFIX, MIN, IF_NOT_NU...
79+
#include "utils/random.h" // for ug_rand
7980
#include "utils/text.h" // for get_font_candidates
8081
#include "utils/thread.h" // for set_thread_name
8182
#include "video.h" // for get_video_desc_from_string
@@ -386,12 +387,12 @@ add_noise(unsigned char *data, size_t len, unsigned bpp, unsigned noisiness)
386387
return;
387388
}
388389
unsigned char *end = data + len;
389-
data += bpp * (rand() % noisiness);
390+
data += bpp * (ug_rand() % noisiness);
390391
while (data < end) {
391392
for (unsigned i = 0; i < bpp; ++i) {
392-
data[i] = rand() % 256;
393+
data[i] = ug_rand() % (UCHAR_MAX + 1);
393394
}
394-
data += bpp * (1 + (rand() % noisiness));
395+
data += bpp * (1 + (ug_rand() % noisiness));
395396
}
396397
}
397398

0 commit comments

Comments
 (0)