svace issues fixed
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginParamCodec.cpp
index bb40be6..0b952bd 100755 (executable)
@@ -46,31 +46,37 @@ int SmsPluginParamCodec::encodeAddress(const SMS_ADDRESS_S *pAddress, char **ppP
 
        SMS_TON_T ton;
 
-       *ppParam = new char[MAX_ADD_PARAM_LEN];
+       char *tempParam = new char[MAX_ADD_PARAM_LEN];
+       if (tempParam == NULL)
+               return 0;
+
+       memset(tempParam, 0x00, sizeof(char)*MAX_ADD_PARAM_LEN);
 
        /* Set Address Length */
        if (temp[0] == '+') {
-               (*ppParam)[offset++] = strlen(temp) - 1;
+               tempParam[offset++] = strlen(temp) - 1;
                temp++;
 
                ton = SMS_TON_INTERNATIONAL;
        } else {
-               (*ppParam)[offset++] = strlen(temp);
+               tempParam[offset++] = strlen(temp);
 
                ton = pAddress->ton;
        }
 
        /* Set TON, NPI */
-       (*ppParam)[offset++] = 0x80 + (ton << 4) + pAddress->npi;
+       tempParam[offset++] = 0x80 + (ton << 4) + pAddress->npi;
 
-       MSG_DEBUG("Address length is %d.", (*ppParam)[0]);
+       MSG_DEBUG("Address length is %d.", tempParam[0]);
        MSG_DEBUG("pAddress->ton : %d.", ton);
        MSG_DEBUG("pAddress->npi : %d.", pAddress->npi);
 
-       length = convertDigitToBcd(temp, strlen(temp), (unsigned char *) &((*ppParam)[offset]));
+       length = convertDigitToBcd(temp, strlen(temp), (unsigned char *) &(tempParam[offset]));
 
        offset += length;
 
+       *ppParam = tempParam;
+
        return offset ;
 }
 
@@ -112,7 +118,7 @@ int SmsPluginParamCodec::encodeTime(const SMS_TIMESTAMP_S *pTimeStamp, char **pp
 
 int SmsPluginParamCodec::encodeDCS(const SMS_DCS_S *pDCS, char **ppParam)
 {
-       *ppParam = new char;
+       *ppParam = new char[MAX_DCS_PARAM_LEN];
 
        **ppParam = 0x00;
 
@@ -164,7 +170,7 @@ int SmsPluginParamCodec::encodeDCS(const SMS_DCS_S *pDCS, char **ppParam)
                return 0;
        }
 
-       return 1;
+       return MAX_DCS_PARAM_LEN;
 }
 
 
@@ -278,7 +284,7 @@ int SmsPluginParamCodec::decodeAddress(const unsigned char *pTpdu, SMS_ADDRESS_S
                convertBcdToDigit(&(pTpdu[offset]), bcdLen, &((pAddress->address)[0]));
        }
 
-       offset +=       bcdLen;
+       offset +=       bcdLen;
 
 /*     MSG_DEBUG("address [%s]", pAddress->address);
 */
@@ -515,7 +521,8 @@ time_t SmsPluginParamCodec::convertTime(const SMS_TIMESTAMP_S *time_stamp)
                MSG_DEBUG("timezone : %d", time_stamp->time.absolute.timeZone);
 
                char displayTime[32];
-               struct tm * timeTM;
+               struct tm timeTM;
+               memset(&timeTM, 0x00, sizeof(tm));
 
                struct tm timeinfo;
                memset(&timeinfo, 0x00, sizeof(tm));
@@ -541,9 +548,9 @@ time_t SmsPluginParamCodec::convertTime(const SMS_TIMESTAMP_S *time_stamp)
 
                rawtime -= (time_stamp->time.absolute.timeZone * (3600/4));
 
-               timeTM = localtime(&rawtime);
+               localtime_r(&rawtime, &timeTM);
                memset(displayTime, 0x00, sizeof(displayTime));
-               strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
+               strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeTM);
                MSG_DEBUG("displayTime [%s]", displayTime);
 
 /* timezone value is tiemzone + daylight. So should not add daylight */
@@ -553,9 +560,10 @@ time_t SmsPluginParamCodec::convertTime(const SMS_TIMESTAMP_S *time_stamp)
                rawtime -= timezone;
 #endif
 
-               timeTM = localtime(&rawtime);
+               memset(&timeTM, 0x00, sizeof(tm));
+               localtime_r(&rawtime, &timeTM);
                memset(displayTime, 0x00, sizeof(displayTime));
-               strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
+               strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeTM);
                MSG_DEBUG("displayTime [%s]", displayTime);
        } else {
                rawtime = time(NULL);