Fix svace_2.3 defects
[platform/core/security/drm-service-core-tizen.git] / tadcore / TADCCore / TADC_Util.cpp
index 4f08b07..bde66c4 100644 (file)
@@ -20,6 +20,8 @@
 #include "TADC_IF.h"
 #include "TADC_ErrorCode.h"
 
+#include <string>
+
 // -------------------------- Base64 --------------------------------
 static CHAR __base64_table[] = {
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
@@ -166,30 +168,20 @@ LPBYTE Base64Decode(LPCSTR pszString, int *pnLength)
 
 int HEX2BIN(LPCSTR pszHex, LPBYTE baBin, int *pnLength)
 {
-       CHAR szTemp[3];
-       CHAR szHex[1024];
-       int i = 0, nLength = 0;
-
-       nLength = TADC_IF_StrLen(pszHex);
-
-       if (nLength <= 0)
+       int hexLen = strlen(pszHex);
+       if (hexLen <= 0)
                return -1;
 
-       if ((nLength % 2) == 0) {
-               TADC_IF_StrNCpy(szHex, pszHex, nLength);
-       } else {
-               szHex[0] = '0';
-               TADC_IF_StrNCpy(&szHex[1], pszHex, nLength);
-               nLength += 1;
+       std::string hex(pszHex);
+       if ((hexLen % 2) != 0) {
+               hex.insert(0, "0");
+               hexLen++;
        }
 
-       *pnLength = nLength / 2;
-       szTemp[2] = 0;
-
-       for (i = 0; i < *pnLength; i++) {
-               szTemp[0] = szHex[i * 2];
-               szTemp[1] = szHex[i * 2 + 1];
-               baBin[i] = (BYTE)strtoul(szTemp, NULL, 16);
+       *pnLength = hexLen / 2;
+       for (int i = 0; i < *pnLength; i++) {
+               char buf[3] = {hex.at(i * 2), hex.at(i * 2 +1), '\0'};
+               baBin[i] = (BYTE)strtoul(buf, NULL, 16);
        }
 
        return 0;