FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add malloc.h into StandardCLibrary.h. by ahuo-dev · Pull Request #1835 · cpputest/cpputest · GitHub

Add malloc.h into StandardCLibrary.h. - #1835

Open
ahuo-dev wants to merge 1 commit into
cpputest:masterfrom
ahuo-dev:dev/ahuo/cpputest_header_add_malloc_h
Open

Add malloc.h into StandardCLibrary.h.#1835
ahuo-dev wants to merge 1 commit into
cpputest:masterfrom
ahuo-dev:dev/ahuo/cpputest_header_add_malloc_h

Conversation

ahuo-dev commented Jan 2, 2025

Copy link
Copy Markdown

Add malloc.h into StandardCLibrary.h. Some C code include malloc.h for malloc func.

thetic commented Jan 2, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

Per the standard, malloc is declared in stdlib.h1 which is already included.

Footnotes

  1. https://en.cppreference.com/w/c/memory/malloc

basvodde commented Jan 2, 2025

Copy link
Copy Markdown
Member

@ahuo-dev Could you share what environment you were trying to solve what problem, then we can look at whether this is the best fix.

ahuo-dev commented Jan 2, 2025

Copy link
Copy Markdown
Author

Per the standard, malloc is declared in stdlib.h1 which is already included.

Footnotes

  1. https://en.cppreference.com/w/c/memory/malloc

@ahuo-dev Could you share what environment you were trying to solve what problem, then we can look at whether this is the best fix.

@basvodde My project use amazonaws kinesis video stream code. I have a compile error when enable cpputest memory leak check . and I found amazonaws kinesis video stream code use malloc header with malloc.h. see this code line 523 at https://github.com/awslabs/amazon-kinesis-video-streams-pic/blob/master/src/common/include/com/amazonaws/kinesis/video/common/CommonDefs.h

basvodde commented Jan 9, 2025

Copy link
Copy Markdown
Member

Ok, but the include of #malloc.h in the CommonDef.h shouldn't need to trigger you to include it in the SatndardCLibrary.h, right?

Could you share what the compile error is that you are getting?

Copy link
Copy Markdown
Author

Ok, but the include of #malloc.h in the CommonDef.h shouldn't need to trigger you to include it in the SatndardCLibrary.h, right?

Could you share what the compile error is that you are getting?

Compile error message :
"nclude/CppUTest/MemoryLeakDetectorMallocMacros.h:36:47: error: expected declaration specifiers or ‘...’ before string constant
36 | #define malloc(a) cpputest_malloc_location(a, FILE, LINE)"

and run command "gcc -E " to expand all macro. I see malloc function prototype expand to cpputest_malloc_location, like this :
extern void *

38 "/usr/include/malloc.h"

        cpputest_malloc_location(

38 "/usr/include/malloc.h" 3 4

        size_t __size

38 "/usr/include/malloc.h"

        , "/usr/include/malloc.h", 38)

38 "/usr/include/malloc.h" 3 4

                               __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__))
 __attribute__ ((__alloc_size__ (1))) ;

Normally it should be like this:
extern void *malloc (size_t __size) __THROW attribute_malloc
attribute_alloc_size ((1)) __wur;

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL