From 5969a4b5e0fb2ab017b05b43d5341a117ce46825 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 27 Jun 2022 23:59:20 +0200 Subject: [PATCH] Don't call memcpy(NULL, 0) which has undefined behavior Signed-off-by: Gilles Peskine --- tests/suites/test_suite_asn1write.function | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/suites/test_suite_asn1write.function b/tests/suites/test_suite_asn1write.function index 8c260f767..4ed8644f0 100644 --- a/tests/suites/test_suite_asn1write.function +++ b/tests/suites/test_suite_asn1write.function @@ -417,9 +417,12 @@ void test_asn1_write_bitstrings( data_t *bitstring, int bits, #if defined(MBEDTLS_ASN1_PARSE_C) ASSERT_ALLOC( masked_bitstring, byte_length ); - memcpy( masked_bitstring, bitstring->x, byte_length ); - if( bits % 8 != 0 ) - masked_bitstring[byte_length - 1] &= ~( 0xff >> ( bits % 8 ) ); + if( byte_length != 0 ) + { + memcpy( masked_bitstring, bitstring->x, byte_length ); + if( bits % 8 != 0 ) + masked_bitstring[byte_length - 1] &= ~( 0xff >> ( bits % 8 ) ); + } size_t value_bits = bits; if( is_named ) {