[PATCH] Initialize the random number generator

Miika Turkia miika.turkia at gmail.com
Wed Feb 24 06:37:33 PST 2016


We use random numbers for file names, both temporary filename when
creating a zip for divelogs.de upload and for filename on form data for
facebook upload. This does not require for true randomness but we still
want these to not be constant on each run of Subsurface. Thus we need to
initialize the random number generator.

Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
---
I noticed this when I was testing the divelogs.de upload. I always ended
up with same file name when removing the deletion of the temporary .dld.
And of course I had problems adding the same files again to the already
existing zip.
---
 subsurface-desktop-main.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp
index d084f2a..2b7bf89 100644
--- a/subsurface-desktop-main.cpp
+++ b/subsurface-desktop-main.cpp
@@ -64,6 +64,14 @@ int main(int argc, char **argv)
 #else
 	git_libgit2_init();
 #endif
+	/*
+	 * Initialize the random number generator - not really secure as
+	 * this is based only on current time, but it should not matter
+	 * that much in our context. Moreover this is better than
+	 * the constant numbers we used to get before.
+	 */
+	qsrand(time(NULL));
+
 	setup_system_prefs();
 	copy_prefs(&default_prefs, &prefs);
 	fill_profile_color();
-- 
2.5.0



More information about the subsurface mailing list