Need help on Bus error(coredump)

Hi all,

I am quite weak in C but I need to get some work done. Hope someone can help me out. I keep getting this error when i try to run my C application in my HP-UX 10.20 machine.

Some code snippet:

Month(DBTime) =====This is a function which will return variable "CutOffTime" to be use below
strcpy(DBSecTime, CutOffTime)
sprintf(str, "DBSecTime is : %s\n", DBSecTime);
InputLog(Log, str);

exec sql begin works;
sprintf(str, "DBSecTime is : %s\n", DBSecTime);
InputLog(Log, str);

exec sql select * from tableA where time < :DBSecTime

exec sql commit work;

I am able to print out values of DBSecTime on every sprintf until I reach the sql statement, following which, a Bus error(coredump) will appear.

Hope someone is able to give me some advices. Thanks in advance. :slight_smile:

You should include more code, such as the declaration of DBSecTime. And what is this ?

exec sql select * from tableA where time < :DBSecTime

That's not C code.

Lets start simple:
What does

 file core

return?

Hi otheus, sorry about that, I have included more codes.

exec sql begin declare section;
char DBSecTime[15];
exec sql end declare section;

Month(DBTime) ===== This is a function which will return variable "CutOfftime" to be use below:
strcpy(DBSecTime, CutOffTime)
sprintf(str, "DBSecTime is : %s\n", DBSecTime);
InputLog(Log, str);

exec sql begin works;
sprintf(str, "DBSecTime is : %s\n", DBSecTime);
InputLog(Log, str);

exec sql select * from tableA where time < :DBSecTime

exec sql commit work;

exec sql select * from tableA where time < : DBSecTime, this is actually a embedded sql statement in my C code. I just find it strange that the 2 sprintf statement was able to run smoothly but not the DBSecTime that was in the sql statement. I have even try to replace DBSecTime in the sql statement with a value like "200812000000" and it managed to got thru too. :confused:

Hi vbe, file core return
core: core file from 'Test.exe' - received SIGBUS

Ah. you haven't nul-terminated DBSecTime!! C won\t do that for unless you tell it to.

char DBSecTime[15] = { 0 };