mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Add test helper function unhexify_alloc()
This commit is contained in:
		
							parent
							
								
									88aa6e0b58
								
							
						
					
					
						commit
						3d49b9d220
					
				@ -2,6 +2,13 @@
 | 
			
		||||
#include "polarssl/memory.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if defined(POLARSSL_PLATFORM_C)
 | 
			
		||||
#include "polarssl/platform.h"
 | 
			
		||||
#else
 | 
			
		||||
#define polarssl_malloc     malloc
 | 
			
		||||
#define polarssl_free       free
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#include <basetsd.h>
 | 
			
		||||
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().
 | 
			
		||||
 * Although predictable and often similar on multiple
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user