Add test helper function unhexify_alloc()

This commit is contained in:
Manuel Pégourié-Gonnard 2014-06-06 14:48:09 +02:00
parent 88aa6e0b58
commit 3d49b9d220

View file

@ -2,6 +2,13 @@
#include "polarssl/memory.h" #include "polarssl/memory.h"
#endif #endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_malloc malloc
#define polarssl_free free
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#include <basetsd.h> #include <basetsd.h>
typedef UINT32 uint32_t; typedef UINT32 uint32_t;
@ -94,6 +101,27 @@ static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
} }
} }
/**
* Allocate and fill a buffer from hex data.
*
* The buffer is sized exactly as needed. This allows to detect buffer
* overruns (including overreads) when running the test suite under valgrind.
*
* For convenience, dies if allocation fails.
*/
static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
{
unsigned char *obuf;
*olen = strlen(ibuf) / 2;
assert( ( obuf = polarssl_malloc( *olen ) ) != NULL );
(void) unhexify( obuf, ibuf );
return( obuf );
}
/** /**
* This function just returns data from rand(). * This function just returns data from rand().
* Although predictable and often similar on multiple * Although predictable and often similar on multiple