Runtime Error R6003 integer divide by zero

I am getting a run-time error in my C++ application and I have tried to track this down in my code using the primitive debugger that they have and have had no luck at all finding this. I am not sure if allocating dynamic memory and then freeing the memory would cause this kind of error. I am not doing any kind of Math operations as the error suggests. I will say I am running a very old version of MS C++ version 1.56 which I am stuck with for the time being. This application runs on a hand-held scanning device and scans barcodes.

Any other possible causes for this error?

Any help would greatly be appreciated.
Can you post your code?
/* -Form3-
Label : Serial
Label : lbl8
Text : SERIALtxt
Label : lbl3
Label : lbl4
*/

#include "fm.h"
#include "main.h"
#include "stdlib.h"
#include "string.h"

/*---- These C functions are used in the Examination of the Array Buffer */
/* and the Serial Numbers being scanned */
/*-----------------------------------------------------------------------*/

/* */
/* Check to see if what was scanned is already in the buffer */
/* */
int isDuplicate(char **myBuff, char *mySERIALtxt, int MaxArraySize)
{
int DuplicateFlag, w;

DuplicateFlag = 0;
for (w=0; w < MaxArraySize; w++)
{
if (strcmp(myBuff[w], mySERIALtxt) == 0)
{
DuplicateFlag = 1;
w = MaxArraySize;
}
}
return DuplicateFlag;
}

/* */
/* If the Serial Number is Deleted on a Recall then re-adjust the array buffer */
/* */
void adjustMyBuffer(char **myBuff, int MaxArraySize)
{
int z;
int adjustflag;
for (z=0; z < MaxArraySize; z++)
{
strcpy(myBuff[z], myBuff[z+1]);
adjustflag = 1;

} /*End For Loop */
} /* End Function */

int ShowForm3(ProgStruct *ps)
{
int tc; /* terminating code */
int rc; /* return code for next form */
int more; /* loop variable */
int hasPrefix; /* Prefix Check for Serial Number*/
int i, x, k, y=0, r=1; /* loop variables */
int isDataGood;
int myBufferSize = 10; /* Set Buffer to 5 for testing */
int myFieldSize = 12;
int BufferCount;
int CurrentPosition;
char SERIALtxt[12];
char NewSerial[12];
char strDate[9];
char strTime[5];
char **myBuffer;
FILE *chan;

more = 1;
BufferCount = 0;
fmClearFlds(Form3); /* clear text boxes */

myBuffer = (char**) malloc(myBufferSize * sizeof(char *)); /* Allocate an array */

for (i = 0; i < myBufferSize; i++)
{
myBuffer[i] = (char*)malloc(myFieldSize);
memset(myBuffer[i], 0, myFieldSize);
strcpy(myBuffer[i], "");
}

memset(strDate, 0, sizeof(strDate));
memset(strTime, 0, sizeof(strTime));
strncpy(strDate, ps->e, 4);
strncat(strDate, ps->f, 2);
strncat(strDate, ps->g, 2);
strncpy(strTime, ps->h, 2);
strncat(strTime, ps->i, 2);

while (more)
{
if (ps->ReturnToMain) /* return to main menu */
return tc;

tc = fmProcForm(Form3);

switch (tc)
{
case fmF1: /* Recall and Display Last Bufferred Serial Number */
if (x >= 0 && BufferCount >0)
{
x--;
fmSetFld(Form3,"SERIALtxt", myBuffer[x]);
fmSetFocus(Form3,"SERIALtxt");
}
break;
case fmF3: /*F3-Delete pressed - Remove from the Array and re-adjust the buffer */
fmGetFld(Form3,"SERIALtxt",SERIALtxt);
if (strcmp(SERIALtxt, "") != 0 && BufferCount >0)
{
fmClearFlds(Form3);
strcpy(SERIALtxt, "");
strcpy(myBuffer[x], SERIALtxt);
fmSetFld(Form3,"SERIALtxt", myBuffer[x]);
fmSetFocus(Form3,"SERIALtxt");
adjustMyBuffer(myBuffer,myBufferSize);
BufferCount--;
y--;
}else{
fmBuzz();
fmMsg("Error","Invalid","Serial Number");
tc = fmProcForm(Form3);
}
fmClearFlds(Form3);
r = 1;
fmSetFocus(Form3,"SERIALtxt");
break;
case fmF4:
break;
case fmMode: /*ESC Exit pressed - Write out the remaining items in the Buffer */
chan=fopen("BTDATA.TXT", "a");
while (strcmp(myBuffer[0],"") != 0 && strcmp(myBuffer[0], NULL) != 0)
{
if (strcmp(myBuffer[0], "") != 0 && strcmp(myBuffer[0], NULL) != 0)
{
char outbuff[128];
sprintf(outbuff, "%s,%s,%s,%s,%s,%s,%s\n", ps->a,ps->b,ps->c,ps->d,strDate,strTime,myBuffer[0]);
fwrite(outbuff, sizeof(char), strlen(outbuff), chan);
strcpy(myBuffer[0], "");
adjustMyBuffer(myBuffer,myBufferSize);
}
}

for (i = 0; i < myBufferSize; i++)
{
free(myBuffer[i]); /* Free the buffer memory allocated */
}

free(myBuffer); /* Free the character pointer allocated */

fclose(chan);
BufferCount=0;
break;
more = 0;
ShowForm1(ps); /* clear text boxes */
case fmEnter: /*Enter or Scan was executed - Move into Buffer */
fmGetFld(Form3,"SERIALtxt",SERIALtxt);
if(r == 0)
r = 1;

for(i=0;i<r;i++)
{
isDataGood = 0;
memset(NewSerial, 0, sizeof(NewSerial));

/* Remove the S/N Prefix */
if ((strlen(SERIALtxt) > 0) && strncmp(SERIALtxt, "S/N", 3) == 0)
{
k = 0;
isDataGood = 1;
for(i=3;i< strlen(SERIALtxt); i++)
{
if (isdigit(SERIALtxt[i]))
{
NewSerial[k] = SERIALtxt[i];
k++;
}
}
}

if ((strlen(SERIALtxt) > 0) && strncmp(SERIALtxt, "S/N", 3) != 0){

if (strncmp(SERIALtxt, "P/N", 3) == 0) isDataGood = 0;
else if (strncmp(SERIALtxt, "QTY", 3) == 0) isDataGood = 0;
else if (strncmp(SERIALtxt, "L/N", 3) == 0) isDataGood = 0;
else
{
strcpy(NewSerial, SERIALtxt);
isDataGood = 1;
}
}

if (isDataGood && tc != 5)
{
if (!(isDuplicate(myBuffer, NewSerial, myBufferSize)))
{
if (SERIALtxt != "" || SERIALtxt != NULL)
{
if (BufferCount == myBufferSize) /* check to see if buffer is full before adding more serial numbers */
{
char outbuff[128];
sprintf(outbuff, "%s,%s,%s,%s,%s,%s,%s\n", ps->a,ps->b,ps->c,ps->d,strDate,strTime,myBuffer[0]);
chan=fopen("BTDATA.TXT", "a");
fwrite(outbuff, sizeof(char), strlen(outbuff), chan);
fclose(chan);
CurrentPosition--;
BufferCount--;

strcpy(myBuffer[0], ""); /* Put "" in its place so it knows where to adjust from */
adjustMyBuffer(myBuffer,myBufferSize);
y--; /* position back to the beginning of the array */
}

strcpy(myBuffer[y], NewSerial);
y++;
CurrentPosition = y;
BufferCount++;
x = BufferCount;
fmBeep();
}
}else{
fmBuzz();
fmMsg("Error","Duplicate Serial","Number Detected");
break;
}
}else{
if (tc != 5)
{
fmBuzz();
fmBuzz();
fmBuzz();
CurrentPosition = y;
fmMsg("Error","Invalid","Serial Number");
fmSetFocus(Form3,"SERIALtxt");
y = CurrentPosition;
}
}
}
isDataGood = 0;
fmClearFlds(Form3);
r = 1;
fmSetFocus(Form3,"SERIALtxt");
break;
}

} /* while more */
return tc;
}

Any ideas of what might be causing the runtime error?
use code tags.
What is a code tag?
Topic archived. No new replies allowed.