tinyds: use 'rand_r' instead of function 'rand' 95/280795/1
authorduna.oh <duna.oh@samsung.com>
Fri, 2 Sep 2022 06:36:57 +0000 (15:36 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 5 Sep 2022 07:53:42 +0000 (16:53 +0900)
For thread safety, rand_r is preferred to use.

Change-Id: I6076f937595480a28fb83e9efadc02e53f345542

examples/tinyds.c

index 91f2965..32087e6 100644 (file)
@@ -1108,6 +1108,8 @@ view_handle_xdg_surface_destroy(struct wl_listener *listener, void *data)
 static void
 view_handle_surface_commit(struct wl_listener *listener, void *data)
 {
+    static unsigned int seedx = 1;
+    static unsigned int seedy = 43210;
     struct tinyds_view *view;
     struct ds_buffer *buffer;
     int w = 0, h = 0;
@@ -1121,8 +1123,8 @@ view_handle_surface_commit(struct wl_listener *listener, void *data)
 
         ds_buffer_get_size(buffer, &w, &h);
 
-        view->x = rand() % (OUTPUT_WIDTH - w);
-        view->y = rand() % (OUTPUT_HEIGHT - h);
+        view->x = rand_r(&seedx) % (OUTPUT_WIDTH - w);
+        view->y = rand_r(&seedy) % (OUTPUT_HEIGHT - h);
     }
 
     output_damage(view->server->output);