This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/CCSTUDIO: memory allocated with wrong size by malloc function

Part Number: CCSTUDIO
Other Parts Discussed in Thread: AM3352

Tool/software: Code Composer Studio

IDE: 8.2.0

compiler: TI v5.2.5

chip: am3352

image: https://imgur.com/a/TOhHuqW

The allocation size for malloc function is sizeof(pl_s) + dataLen(4+98), but the Expression window shows very large number(7405568) of data size.

Why? Thanks.

  • Andy,

    I see a few places for a potential errors.
    How do you define pl_s struct?
  • I'm not sure what is happening.  For the source file DNM_PktXcvr.c, please submit a test case as described in the article How to Submit a Compiler Test Case.  I may be able to explain everything from that alone.  But, if not, I will be able to ask better questions.

    Thanks and regards,

    -George

  • Tomasz,
    Thanks for your reminder. How can I forget to post struct pl_s?

    typedef struct __attribute__((__packed__))
    {
    u16 type;
    u16 len;
    u8 data[0];
    }pl_s; //payload
  • George,

    Here is my Compiler Test Case:

    DNM_PktXcvr.pp.txt

    "C:/ti/ccsv8/tools/compiler/ti-cgt-arm_5.2.5/bin/armcl" -mv7A8 --code_state=32 --float_support=VFPv3 --abi=eabi -me --include_path="C:/ti/ccsv8/tools/compiler/ti-cgt-arm_5.2.5/include" --include_path="C:/ti/ccsv8/ATEIS AM335X/Include" --include_path="C:/ti/ccsv8/ATEIS AM335X/Include/uCOS Include" --include_path="C:/ti/ccsv8/ATEIS AM335X/Include/NandFlash Include" --include_path="C:/ti/ccsv8/ATEIS AM335X/Include/lwip Include" --include_path="C:/ti/ccsv8/ATEIS AM335X/Include/FatSystem" --include_path="C:/ti/ccsv8/ATEIS AM335X/Include/MP3" --include_path="C:/ti/ccsv8/ATEIS AM335X/Include/OSIP" --include_path="C:/ti/ccsv8/ATEIS AM335X/Include/RTP" --include_path="C:/ti/ccsv8/ATEIS AM335X/Include/mmcsdlib" --include_path="C:/ti/ccsv8/ATEIS AM335X/Source Code/Include" --include_path="C:/ti/ccsv8/ATEIS AM335X/Source Code/Include/hw" --include_path="C:/ti/ccsv8/ATEIS AM335X/Source Code/Include/armv7a" --include_path="C:/ti/ccsv8/ATEIS AM335X/Source Code/Include/armv7a/am335x" --include_path="C:/ti/ccsv8/ATEIS AM335X/NANDFlash_Programmer/BurnIN_NAND/Web/httpserver_raw" -g --preproc_with_comment --preproc_with_compile --define=am3352 --define=AM335X --define=_FUNCTION_PERFORMANCE_xx --diag_warning=225 --diag_wrap=off --display_error_number --neon --enum_type=int --wchar_t=16 -k --src_interlist --obj_directory="MCU"  "../MCU/DNM_PktXcvr.c"

    Compiler: arm_5.2.5

    Thank you!

  • Thank you for the test case.  I suspect this is a problem only in how CCS displays the field data inside the pl_s structure.

    Your C code defines this structure type ...

    typedef struct __attribute__((__packed__))
    {
    	unsigned short type;
    	unsigned short len;
    	unsigned char data[0];
    }pl_s;	//payload
    

    I think CCS is mishandling that zero length structure in the display.  

    When you run through the code without stopping, does everything work as expected?  For now, I presume it does.

    I have notified the CCS experts about this issue.  Expect to hear from them next.

    Thanks and regards,

    -George

  • This appears to be a bug with the debugger. I filed a bug. Tracking ID: CCBT-2385

    Thanks
    ki
  • Thank you both!
  • no problem by far , thanks!
  • Hello Andy,
    could you check how does it performs when you replace
    u8 data[0];
    with
    u8* data;
    ???
  • image: https://imgur.com/a/fd8nkgM

    As you want, I changed member u8 data[0] to u8* data.

    Screenshots are the result. If you want more scenarios, please tell me. Thanks.

  • It looks like the expression free (payload_p) in line 166 destroys what you have achieved in lines 163-165.