Skip to content

Commit

Permalink
Merge pull request lucasjones#3 from erkmos/osxfix
Browse files Browse the repository at this point in the history
Segfault and compilation error on OSX10.9 and FreeBSD 10 with clang
  • Loading branch information
lucasjones committed May 22, 2014
2 parents 5db4950 + 79a4772 commit adce8dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crypto/oaes_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ static const char _NR[] = {
#include <stddef.h>
#include <time.h>
#include <sys/timeb.h>
#if !((defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__APPLE__))
#include <malloc.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down
10 changes: 8 additions & 2 deletions cryptonight.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ void cryptonight_hash_ctx(void* output, const void* input, size_t len, struct cr
}

void cryptonight_hash(void* output, const void* input, size_t len) {
cryptonight_hash_ctx(output, input, len, alloca(sizeof(struct cryptonight_ctx)));
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));
cryptonight_hash_ctx(output, input, len, ctx);
free(ctx);
}

void cryptonight_hash_ctx_aes_ni(void* output, const void* input, size_t len, struct cryptonight_ctx* ctx) {
Expand Down Expand Up @@ -269,14 +271,15 @@ int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
const uint32_t Htarg = ptarget[7];
uint32_t hash[HASH_SIZE / 4] __attribute__((aligned(32)));

struct cryptonight_ctx *ctx = alloca(sizeof(struct cryptonight_ctx));
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));

if (aes_ni) {
do {
*nonceptr = ++n;
cryptonight_hash_ctx_aes_ni(hash, pdata, 76, ctx);
if (unlikely(hash[7] < ptarget[7])) {
*hashes_done = n - first_nonce + 1;
free(ctx);
return true;
}
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));
Expand All @@ -286,10 +289,13 @@ int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
cryptonight_hash_ctx(hash, pdata, 76, ctx);
if (unlikely(hash[7] < ptarget[7])) {
*hashes_done = n - first_nonce + 1;
free(ctx);
return true;
}
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));
}

free(ctx);
*hashes_done = n - first_nonce + 1;
return 0;
}

0 comments on commit adce8dc

Please sign in to comment.