Skip to content
This repository was archived by the owner on Jan 28, 2020. It is now read-only.

Use rand() for randombytes #1

Merged
merged 2 commits into from
Mar 2, 2018
Merged

Use rand() for randombytes #1

merged 2 commits into from
Mar 2, 2018

Conversation

danimtb
Copy link
Member

@danimtb danimtb commented Mar 2, 2018

I dont know if rand() is multiplatform, but I had problems with defines for WIN32...
http://www.cplusplus.com/reference/cstdlib/rand/

So I guess that better to keep it simple. WDYT?

Yes, I took this example from other repo using this library. But I would do this:

diff --git a/test_package/example.cpp b/test_package/example.cpp
index af944d8..b7490d3 100644
--- a/test_package/example.cpp
+++ b/test_package/example.cpp
@@ -4,21 +4,24 @@ extern "C" {
 #include "tweetnacl.h"

 /* Library needs external randombytes implemented */
-#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>

 void randombytes(unsigned char * ptr,unsigned int length)
 {
+    int i;
     srand(time(NULL));
-    ptr = new unsigned char(rand());
+
+    for (i = 0; i < length; i++) {
+        ptr[i] = (unsigned char)rand();
+    }
 }

 #ifdef __cplusplus
 }
 #endif

-
+#include <stdio.h>
 #include <stdexcept>
 #include <string.h>

Are you OK if I change this PR?

@danimtb
Copy link
Member Author

danimtb commented Mar 2, 2018

test_package was failing with:

Generating random data failed. Please report this to https://github.com/ultramancool

@danimtb
Copy link
Member Author

danimtb commented Mar 2, 2018

good for me!

@pvicente pvicente merged commit c88eb13 into conan-community:stable/20140427 Mar 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants