none
First-chance exception at 0x004115cf in Compass_code.exe: 0xC0000005: Access violation writing location 0x00130000. RRS feed

  • 问题

  • Hi guys,

    When I run the following C code in vs2005, It coudn't print all the data. And there is the error "First-chance exception at 0x004115cf in Compass_code.exe: 0xC0000005: Access violation writing location 0x00130000."

    -------------------------------

    #include<stdio.h>
    #include<stdlib.h>

    typedef unsigned int    UINT32;
    typedef int             INT32;
    typedef unsigned long   DWORD;

    const static UINT32 G2INIT[2] ={42,15};

    /**
    * \fn void genCodeCompass()
    * \brief Generate the PRN code sequence for Compass E2/E5b
    * \param[in] svId is the PRN ID of Compass satellite
    * \param[in] generatedCode is the pointer to the generated code
    * \return void
    */
    //static void genCodeCompass(INT32 prnId)
    static void genCodeCompass(INT32 prnId, DWORD* generatedCode)
    {
        UINT32 G1, G2, tmp, i, i2;
        UINT32 genBlock;

        G1 = 682;
        G2 = G2INIT[prnId];
        for (i=0;i<64;i++)
        {
            genBlock = 0;
            for (i2=0;i2<32;i2++)
            {
                // Store the current PRN chip.
                genBlock |= (((G1>>10)&1) ^((G2>>10)&1)) << i2;
                // Progress G1 and G2.
                tmp = ((G1>>0)&1)^((G1>>6)&1)^((G1>>7)&1)^((G1>>8)&1)^((G1>>9)&1)^((G1>>10)&1);
                G1 = (G1<<1)&2047;
                G1 |= tmp;
                tmp = ((G2>>0)&1) ^((G2>>1)&1) ^((G2>>2)&1) ^((G2>>3)&1) ^((G2>>4)&1) ^((G2>>7)&1)^((G2>>8)&1) ^((G2>>10)&1);
                G2 = (G2<<1)&2047;
                G2 |= tmp;
            }
           generatedCode[i] = genBlock;
      printf("%x\n",generatedCode[i]);
      
        }

    }

    int main()
    {
     INT32 Id=1;
     DWORD *Code;
     DWORD add=0x0;
     DWORD* p = (DWORD *) malloc ( sizeof(DWORD) * 10000);
     Code=&add;
     genCodeCompass(Id, Code);
     //genCodeCompass(Id);
    }
    ------------------------------------

    Please help me.

    Regards.

    Phoenix

    2011年7月12日 5:44

答案

  • Hi Phoenix,

    The issue is youset the Code which is the pointer to add, but not a pointer to a DWORD array. In function genCodeCompass, you try to set the genBlock to  generatedCode[i]. But the generatedCode just the input parameter Code. If the i > 0, there would be a VA hence you got the exception.

    BRs


    麻烦把正确答案设为解答。
    2011年7月12日 5:53
    版主

全部回复

  • Hi Phoenix,

    The issue is youset the Code which is the pointer to add, but not a pointer to a DWORD array. In function genCodeCompass, you try to set the genBlock to  generatedCode[i]. But the generatedCode just the input parameter Code. If the i > 0, there would be a VA hence you got the exception.

    BRs


    麻烦把正确答案设为解答。
    2011年7月12日 5:53
    版主
  • Hi SplendourG,

    Thanks. I change DWORD add to DWORD add[64]. And it runs OK. But I can't see the output because the output window immediately dispears when comes out. 

    2011年7月12日 6:05
  • I solve the problem now. Thanks.
    2011年7月12日 6:06