--- libelwix/src/str.c 2018/05/31 15:35:16 1.8 +++ libelwix/src/str.c 2023/03/14 22:33:43 1.9.30.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: str.c,v 1.8 2018/05/31 15:35:16 misho Exp $ +* $Id: str.c,v 1.9.30.1 2023/03/14 22:33:43 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2018 +Copyright 2004 - 2019 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -286,7 +286,39 @@ str_Dig2Hex(ait_val_t *digz) for (i = 0, b = AIT_GET_BUF(digz); i < AIT_LEN(digz); i++) { snprintf(szWork, sizeof szWork, "%02hhX", b[i]); - strncat(str, szWork, 2); + strcat(str, szWork); + } + + return str; +} + +/* + * str_Dig2Hex2() - Convert from digit array to Hex string + * + * @digz = Digits array + * @diglen = Array length + * return: NULL nothing to do or error; + * !=0 Allocated new converted string (must be e_free()) +*/ +char * +str_Dig2Hex2(u_char * __restrict digz, int diglen) +{ + register int i; + char szWork[3] = { 0, 0, 0 }, *str; + u_char *b; + + if (!digz || !diglen) + return NULL; + + str = e_malloc(diglen * 2 + 1); + if (!str) + return NULL; + else + memset(str, 0, diglen * 2 + 1); + + for (i = 0, b = digz; i < diglen; i++) { + snprintf(szWork, sizeof szWork, "%02hhX", b[i]); + strcat(str, szWork); } return str;