From cbd98ed1e4a8ece3785c393ec572816f1e3d7221 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sun, 30 Nov 2014 13:53:19 +0800 Subject: [PATCH] coverity 83663 remove random from test client Signed-off-by: Andy Green --- test-server/test-client.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test-server/test-client.c b/test-server/test-client.c index 3f7c8b830..e94dbed67 100644 --- a/test-server/test-client.c +++ b/test-server/test-client.c @@ -137,6 +137,7 @@ callback_lws_mirror(struct libwebsocket_context *context, LWS_SEND_BUFFER_POST_PADDING]; int l = 0; int n; + unsigned int rands[4]; switch (reason) { @@ -144,7 +145,8 @@ callback_lws_mirror(struct libwebsocket_context *context, fprintf(stderr, "callback_lws_mirror: LWS_CALLBACK_CLIENT_ESTABLISHED\n"); - mirror_lifetime = 10 + (random() & 1023); + libwebsockets_get_random(context, rands, sizeof(rands[0])); + mirror_lifetime = 10 + (rands[0] & 1023); /* useful to test single connection stability */ if (longlived) mirror_lifetime += 50000; @@ -178,13 +180,15 @@ callback_lws_mirror(struct libwebsocket_context *context, case LWS_CALLBACK_CLIENT_WRITEABLE: - for (n = 0; n < 1; n++) + for (n = 0; n < 1; n++) { + libwebsockets_get_random(context, rands, sizeof(rands)); l += sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING + l], "c #%06X %d %d %d;", - (int)random() & 0xffffff, - (int)random() % 500, - (int)random() % 250, - (int)random() % 24); + (int)rands[0] & 0xffffff, + (int)rands[1] % 500, + (int)rands[2] % 250, + (int)rands[3] % 24); + } n = libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], l, opts | LWS_WRITE_TEXT);