You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "Gary-Hobson (via GitHub)" <gi...@apache.org> on 2024/10/16 02:43:17 UTC

[PR] sim/heap: malloc returns a valid pointer when allocating 0 bytes. [nuttx]

Gary-Hobson opened a new pull request, #14348:
URL: https://github.com/apache/nuttx/pull/14348

   ## Summary
   The malloc() function allocates size bytes and returns a pointer to the allocated memory.  The memory is not initialized.  If size is 0, then malloc() returns a unique pointer value that can later be successfully passed to free().  (See "Nonportable behavior" for portability issues.)
   
   ## Impact
   
   ## Testing
   sim
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sim/heap: malloc returns a valid pointer when allocating 0 bytes. [nuttx]

Posted by "GUIDINGLI (via GitHub)" <gi...@apache.org>.
GUIDINGLI merged PR #14348:
URL: https://github.com/apache/nuttx/pull/14348


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sim/heap: malloc returns a valid pointer when allocating 0 bytes. [nuttx]

Posted by "yamt (via GitHub)" <gi...@apache.org>.
yamt commented on PR #14348:
URL: https://github.com/apache/nuttx/pull/14348#issuecomment-2415620708

   > The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is 0, then malloc() returns a unique pointer value that can later be successfully passed to free().
   
   do you mean to require host malloc to follow the specific behavior? why?
   
   > (See "Nonportable behavior" for portability issues.)
   
   what exactly are you referring to here?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sim/heap: malloc returns a valid pointer when allocating 0 bytes. [nuttx]

Posted by "Gary-Hobson (via GitHub)" <gi...@apache.org>.
Gary-Hobson commented on PR #14348:
URL: https://github.com/apache/nuttx/pull/14348#issuecomment-2415669014

   Sorry, my commit message may not be clear enough.
   
   > > The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is 0, then malloc() returns a unique pointer value that can later be successfully passed to free().
   > 
   > do you mean to require host malloc to follow the specific behavior? why?
   
   I want to align the behavior of sim_heap(Customized heap manager) and mm_heap(Default heap manager).
   
   The default heap management in nuttx returns a valid memory address when malloc(0), In sim_heap, malloc(0) returns NULL.
   This PR makes malloc(0) in sim_heap return a valid pointer
   
   > 
   > > (See "Nonportable behavior" for portability issues.)
   > 
   > what exactly are you referring to here?
   This part is an excerpt from the man manual,It might be missing some context, I've updated the commit message
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sim/heap: malloc returns a valid pointer when allocating 0 bytes. [nuttx]

Posted by "yamt (via GitHub)" <gi...@apache.org>.
yamt commented on PR #14348:
URL: https://github.com/apache/nuttx/pull/14348#issuecomment-2415754141

   > Sorry, my commit message may not be clear enough.
   > 
   > > > The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is 0, then malloc() returns a unique pointer value that can later be successfully passed to free().
   > > 
   > > 
   > > do you mean to require host malloc to follow the specific behavior? why?
   > 
   > I want to align the behavior of sim_heap(Customized heap manager) and mm_heap(Default heap manager).
   > 
   > The default heap management in nuttx returns a valid memory address when malloc(0), In sim_heap, malloc(0) returns NULL. This PR makes malloc(0) in sim_heap return a valid pointer
   
   to me, this PR seems to make it return whatever host_realloc(..., 0) returns.
   depending on the host os, it might or might not be NULL.
   am i missing something?
   
   if you want to make it return non-NULL, the usual trick is `if (size == 0) { size = 1; }`.
   
   > > > (See "Nonportable behavior" for portability issues.)
   > > 
   > > 
   > > what exactly are you referring to here?
   > 
   > This part is an excerpt from the man manual,It might be missing some context, I've updated the commit message
   
   ok. please don't forget that not everyone uses linux.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org