Error when using memcpy
807578Sep 23 2005 — edited Sep 23 2005Hi Friends,
I am using c code developed long back and i am making modifications to it. This c code is forming a sql string and then making a sybase udpate call.
I saw that the date string which was part of the sql query had some junk and i put a '\0' to null terminate it.
I tested it and i am able to get the correct date string now . But when the client is testing it he says that the test failed. ANd i see that the log file has the sql query in which the data string has some junk .
Will there be any problem with the code if it is run on a different version of solaris that is 64 bit ?
I made the changes and testing it on a 32 bit Solaris system.
here is the related part of the code :
----------------------------------------------------------
static char dateString[20];
static char reportDate[30];
memset(dateString,0x00,sizeof(dateString));
main()
{
setupReportDate(dateString);
}
void setupReportDate(char *tempDate)
{
char yearString[6];
char monthNumString[4];
char dateNumString[4];
/* 19981103 */
memset(yearString,0x00,strlen(yearString));
memset(monthNumString,0x00,strlen(monthNumString));
memset(dateNumString,0x00,strlen(dateNumString));
memset(reportDate,0x00,strlen(reportDate));
/*memccpy(yearString,tempDate,4,4);*/
memcpy(yearString,tempDate,4);
memcpy(monthNumString,(char *)&tempDate[4],2);
memcpy(dateNumString,(char *)&tempDate[6],2);
sprintf(reportDate,"%s/%s/%s",monthNumString,dateNumString,yearString);
reportDate[10]='\0';
}
==================================
The log file has the following content :
-------------------------------------------------
09/23/2005 15:29:58 updateDB: szSQL = .UPDATE ReportLocation set status = "G", reportPathName = "/export/home/sveerama/hs
wreports/20050822/Daily/alan222_F15PH_GD_20050822.csv.zip" where userIDident = 7112 and reportID = 18 and reportType = 1 and s
cheduleType = 1 and date = '08/22/2005'.
----------------------------------------------------------
When the client ran the same code he has the following content in the log file :
---------------------------------------------
09/20/2005 22:21:36 updateDB: fileName = .alan222_F15CH_DD_20050822.csv.zip.
09/20/2005 22:21:36 updateDB: userID = .alan222.
09/20/2005 22:21:36 updateDB: reportID = .F15CH.
09/20/2005 22:21:36 updateDB: reportType = .D.
09/20/2005 22:21:36 updateDB: scheduleMnemonic = .D.
09/20/2005 22:21:36 updateDB: reportPath = ./hswreports/20050822/Daily/alan222_F15CH_DD_20050822.csv.zip.
09/20/2005 22:21:36 updateDB: reportDate = .08/22/2005 '�.
09/20/2005 22:21:36 updateDB: userIDident = 7112
09/20/2005 22:21:36 updateDB: reportID = 19
09/20/2005 22:21:36 updateDB: scheduleType = 1
09/20/2005 22:21:36 updateDB: szSQL = .UPDATE ReportLocation set status = "G", reportPathName =
"/hswreports/20050822/Daily/alan222_F15CH_DD_20050822.csv.zip" where userIDident = 7112 and reportID = 19 and reportType = 3
and scheduleType = 1 and date = '08/22/2005 '�'.
------------------------------------
Could you please advice me ?
Thanks in advance.
Thanks
sveera