Skip to content

Commit

Permalink
Merge pull request #352 from Tarsnap/libcperciva-import
Browse files Browse the repository at this point in the history
libcperciva import
  • Loading branch information
cperciva authored Apr 26, 2022
2 parents 92aab18 + b7ad85c commit 725a54c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libcperciva/alg/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ SHA256_Transform(uint32_t state[static restrict 8],
assert(hwaccel != HW_UNSET);
#endif

switch(hwaccel) {
switch (hwaccel) {
#if defined(CPUSUPPORT_X86_SHANI) && defined(CPUSUPPORT_X86_SSSE3)
case HW_X86_SHANI:
SHA256_Transform_shani(state, block);
Expand Down
8 changes: 8 additions & 0 deletions libcperciva/util/imalloc.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
#ifndef _IMALLOC_H_
#define _IMALLOC_H_

#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>

/**
* imalloc(nrec, reclen):
* Allocate ${nrec} records of length ${reclen}. Check for size_t overflow.
* ${reclen} must not be zero. If ${nrec} is zero, return NULL.
*/
static inline void *
imalloc(size_t nrec, size_t reclen)
{

/* Sanity check. */
assert(reclen != 0);

if (nrec == 0)
return (NULL);

if (nrec > SIZE_MAX / reclen) {
errno = ENOMEM;
return (NULL);
Expand Down
3 changes: 3 additions & 0 deletions libcperciva/util/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ sock_resolve_host(const char * addr, const char * ports)
for (n = 0, r = res; r != NULL; r = r->ai_next)
n++;

/* Sanity check. */
assert(n < SIZE_MAX);

/* Allocate our response array. */
if (IMALLOC(sas, n + 1, struct sock_addr *))
goto err1;
Expand Down
2 changes: 1 addition & 1 deletion perftests/standalone-enc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ main(int argc, char * argv[])
print_hardware("Testing spiped speed limits");

/* Run the desired test. */
switch(desired_test) {
switch (desired_test) {
case 1:
if (hmac_perftest(perfsizes, num_perf,
nbytes_perftest, nbytes_warmup))
Expand Down
2 changes: 1 addition & 1 deletion tests/pthread_create_blocking_np/timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static struct testcase {
warn0(#prev " is after " #next); \
goto err0; \
} \
} while(0)
} while (0)

/* Each test. */
struct info {
Expand Down
2 changes: 1 addition & 1 deletion tests/pushbits/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ main(int argc, char ** argv)
}

/* Run the desired test. */
switch(desired_test) {
switch (desired_test) {
case 1:
if ((filename_in == NULL) || (filename_out == NULL))
usage();
Expand Down

0 comments on commit 725a54c

Please sign in to comment.