GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Dec-2006, 11:36
emanresu emanresu is offline
New Member
 
Join Date: Nov 2006
Location: Essex, UK. (Near London)
Posts: 24
emanresu is on a distinguished road

Pointer initialization causing program abend?


Hi,
Working on an MS C ver6 program I was getting this error:
run-time error R6001
- null pointer assignment

The program worked correctly, but I wanted a clean run so investigated it.

When I tracked down the pointer I hadn't initialized, I corrected the program but it is now abending with Btrieve status 3. Now this usually means the file is not open, but that is not the case here as I got no error from the Open statement. The Btrieve MicroKernel also returns this status code if the application passed an invalid position block for the file, or if the application passed a position block with a client ID other than the client ID used to open the file.

Hence I am wondering if the memory is being corrupted and thus affecting the position block??

Here are some bits 'n' pieces from the program...

some variables, etc.
CPP / C++ / C Code:
#define BTI_DOS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <btrapi.h>
#include <btrconst.h>
#define         B_GETFST        12
#define         B_GETNX         6
#define         EOF_ERR         9
#define         B_GETEQ         5


struct i2aRec
{
   char  Ac_cc      [2];
   char  Ac_c       [1];
   char  Ac_mm      [2];
   char  Ac_nnnn    [6];        
   char  Ac_ss      [2];
   char  Nd_acct    [7];
   char  Bs_cntry   [3];
   char  Ac_type    [2];
   char  Intappfreq [3];
   char  Intbasedys [3];
   char  Matchlnact [13];       
   char  Dt_ac_opnd [6];
   char  Line4      [6];        /*  unpacked  */
   char  SgnRept_bal[1];
   char  Rept_bal   [14];       
   char  Res        [1];
   char  Ucntry     [5];
   char  Bnsindust  [5];
   char  UserICRS   [6];
   char  Crintrt    [9];
   char  Drintrt    [9];
   char  Matur_dat  [6];
   char  Locindu    [5];      
};

char *convData ;      /* pointer to report balance output buffer         */
char *datePtr ;       /* pointer to maturity date output buffer          */
char convTab[] = { 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
int             GLD_BUF_LEN;
int             CRD_BUF_LEN;
int             CUB_BUF_LEN;
int             CCY_BUF_LEN;
int             I1A_BUF_LEN;
int             BNS_BUF_LEN;
int             OUT_BUF_LEN;
struct GLDRec   GLD_REC_BUF,  *pi;
struct crdRec   CRD_REC_BUF,  *pj;
struct cubRec   CUB_REC_BUF,  *pk;
struct ICRSEX1A I1A_REC_BUF,  *pl;
struct i2aRec   OUT_BUF,      *po;
struct ccyRec   CCY_REC_BUF,  *pq;
struct bnsRec   BNS_REC_BUF,  *pp;
char            GLD_POS_BLK[128];
char            CRD_POS_BLK[128];
char            CUB_POS_BLK[128];
char            CCY_POS_BLK[128];
char            BNS_POS_BLK[128];
char            I1A_POS_BLK[128];
char            OUT_POS_BLK[128];
char            GLD_KEY_BUF[2];
char            CRD_KEY_BUF[2];
char            CRD_KEY_VALUE[6],  *crdkey;
char            CUB_KEY_BUF[2];
char            CUB_KEY_VALUE[6],  *cubkey;
char            CCY_KEY_BUF[2];
char            BNS_KEY_BUF[2];
char            I1A_KEY_BUF[2];
char            OUT_KEY_BUF[2];
char            CCY_TABLE[60]= "";
char            BNS_TAB[60]= "";
char            I1A_NAME[60]= "";
char            GLD_NAME[60]= "";
char            CRD_NAME[60]= "";
char            CUB_NAME[60]= "";
char            OUT_NAME[60]="";
char            txt_file[60]="";
char            GL_MEMO[5];
char            GL_ACCT[8];

int             STATUS, cStatus, ck;



main ()
{
   pi = &GLD_REC_BUF;
   pj = &CRD_REC_BUF;
   pk = &CUB_REC_BUF;
   pl = &I1A_REC_BUF;
   po = &OUT_BUF;
   pp = &BNS_REC_BUF;
   pq = &CCY_REC_BUF;

OUT_POS_BLK is the position block in question.

While loop
CPP / C++ / C Code:
/*  Read first GL record  */
   STATUS = BTRV (B_GETFST, GLD_POS_BLK, &GLD_REC_BUF, &GLD_BUF_LEN, GLD_KEY_BUF, 0);

   count = 0;
   readcount = 0;   

   while (STATUS != EOF_ERR)    /* start of main while loop  */
   {

      passflag = 0;


      if (pi->GLDstatus == '@')
       if (strncmp(GL_ACCT,"_____",5) != 0)   
	if (strncmp(GL_ACCT,"     ",5) != 0)   
	 if (strncmp(GL_ACCT,"",5) != 0)   
          if (strncmp(pi->GLDAc_c,"3",1) <= 0)
           if (strncmp(pi->GLDAc_type,"10",2) >= 0)
            if (strncmp(pi->GLDAc_type,"99",2) <= 0)
	     if (strncmp(pi->GLDRept_bal,"00000000000000",14) != 0)  
	      if (strncmp(pi->GLDRept_bal,"0000000000000P",14) != 0)  
               {
                passflag = 1;
               }

     if ( passflag == 0 )
        {
          goto getnxt;
        }
/* <snip> */
CPP / C++ / C Code:
   while (cStatus != EOF_ERR)   /* start of a minor while loop   */
   {
      if (cStatus != 0)
      {
	 emessage("Reading","ICRSEX1A.BTR",cStatus);
	 exit(2);
      }


      if (strncmp(pl->ICAcCC, pi->GLDAc_cc, 2) == 0)  
	if (strncmp(pl->ICAcCX, pi->GLDAc_c, 1) == 0)  
          if (strncmp(pl->ICAcMM, pi->GLDAc_mm, 2) == 0)  
            if (strncmp(pl->ICAcno, pi->GLDAc_nnnn, 6) == 0)     
              if (strncmp(pl->ICAcSS, pi->GLDAc_ss, 2) == 0)  
              {
               memcpy (po->Crintrt, pl->ICCrInt, 9);
               memcpy (po->Drintrt, pl->ICDrInt, 9);

 
     /* Convert BM date format to regular date format  */
		datePtr = (char *)  pl->ICMatDt ;
           /*  THIS NEXT LINE CAUSES THE PROBLEM   */
                convData = (char *) pl->ICMatDt ;    

	       /* copy converted date to output buffer */
	       strncpy (po->Matur_dat,
			dateToString (datePtr, convData), 6);

               cStatus = EOF_ERR;
              }

       if (cStatus != EOF_ERR)
         {  
         cStatus = BTRV (B_GETNX, I1A_POS_BLK, &I1A_REC_BUF, &I1A_BUF_LEN, I1A_KEY_BUF, 0);
         }
   }                      /* end of the minor while loop   */

/* <snip> */
CPP / C++ / C Code:

       /* ERROR WRITING ON FOLLOWING INSERT...   */  
/*  Write ICRS record  */
       STATUS = BTRV (B_INSERT, OUT_POS_BLK, &OUT_BUF, &OUT_BUF_LEN, OUT_KEY_BUF, 0);
        if (STATUS != 0)
         {
	  emessage("Writing","ICRSEX2A.BTR",STATUS);
	  exit(2);
         }

        ++count;
        if ( count % 10 == 0 )
         {
	   printf ("                                                 \r");
	   printf ("%d  record(s) being written.                       \r", count);
         }

getnxt:
/*  Read next GL record  */
      STATUS = BTRV (B_GETNX, GLD_POS_BLK, &GLD_REC_BUF, &GLD_BUF_LEN, GLD_KEY_BUF, 0);
   }          /* end of main while loop  */

   printf ("%d  record(s) written.                          \n", count);


DateToString subroutine
CPP / C++ / C Code:
char *dateToString (char  *inpData, char  *outData)
{
   int      k = 0; 
   int      l = 0;
   char     tempStr [1];
   char     *sDtePtr;                 /* pointer to data buffer            */


   sDtePtr = outData;                 /* assign pointer to output buffer   */
   strcpy (sDtePtr, inpData);         /* copy input data to working buffer */

   for (l = 0; l < 2; l++)
      {
       sDtePtr += l;                  /* mover pointer to second position  */

       for (k = 0 ; k < 11 ; k++)
	  {
	   /* check last byte of the string for 'PQRSTUVWXYZ'       */
	   if (memcmp (sDtePtr, &convTab[k], 1) == 0 )
	      {
	       itoa (k, tempStr, 10);        /* convert numeral to ASCII    */
	       memcpy (sDtePtr, tempStr, 1); /* replace with ASCII          */
	      }
	  }
      }

    sDtePtr -= 2;                 /* move pointer to the front   */
    return (outData);

}

If I remove the line
convData = (char *) pl->ICMatDt ;
then it works but gives me the null pointer run time error.

Any ideas why this is happening? Thanks...
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 04:48
How to read particular memory location ? realnapster C Programming Language 10 10-May-2006 10:11
Pointer Usage in C++: Beginner to Advanced varunhome C++ Forum 0 19-Aug-2005 10:25
[Tutorial] Pointers in C (Part II) Stack Overflow C Programming Language 0 27-Apr-2005 18:36
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 19:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:04.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.