anchao opened a new pull request, #20853:
URL: https://github.com/apache/nuttx/pull/20853

   ## Summary
   
   sched/task: cache common argv lengths on stack setup
   
   nxtask_setup_stackargs() first walks the argv list to calculate the
   string table size, then copies the strings onto the new task stack.  The
   old copy path recalculated string lengths before using strlcpy(), causing
   common argv strings to be scanned more than necessary.
   
   Cache the lengths for a small number of arguments during the sizing pass
   and reuse them during the copy pass.  This keeps the common short argv
   case to a single strlen() plus memcpy() without allocating a length table
   sized by CONFIG_TASK_MAX_ARGS, which may be as large as 256.
   
   For unusually large argv lists, fall back to stpcpy() after the cached
   entries so the function avoids a large temporary stack array while still
   copying strings in one pass during the copy phase.
   
   Also stop scanning immediately after detecting an oversized string table
   or too many arguments, keeping the error path bounded once an error has
   already been found.
   
   Signed-off-by: chao an <[email protected]>
   
   ## Impact
   
   N/A
   
   ## Testing
   
   ```
   sim/nsh
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to