Compared to v2 patch:
The stresep.c file is now first only added, and included into Makefile
after removing unneeded define and include namespace.h.
The memcpy bug from v2 patch was reported upstrem to netbsd, and current file
now includes fix (a better fix from maintener, he also moved strlen out of 
loop).

I changed commit message for 3/6, as Nadav suggested.
Also added comment about loader_parse_cmdline() - its results argv and 
app_cmdline point
to memory of str input param, meaning caller should not free/modify str after 
calling
loader_parse_cmdline.

The std::string is intentionally not used - there is comment about that a bit 
higher
in file.

I did want to do memmove(str-1, str, ), not memmove(str, str+1).
> +            // Multiple consecutive delimiters found. Stresep will write 
> multiple
> +            // '\0' into str. Squash them into one, so that argv will be 
> 'nice',
> +            // in memory consecutive array of C strings.
> +            if (str) {
> +                my_debug("    shift   str %p '%s' <- %p '%s'\n", str-1, 
> str-1, str, str);
> +                memmove(str-1, str, strlen(str) + 1);
> I'm confused... If I understand correctly "str" points to that second
> 0 you want to remove. So shouldn't you copy str+1 to str? why copy str
> to str-1?

justin_cinkelj@jcpc:~/devel/mikelangelo/osv-fc25/osv$ ./scripts/run.py -V -e ' 
--env=AA=aa'
OSv v0.24-442-g4bdaa11
  ap = 0xffff900001510000 --verbose, *ap=45
  ap = 0xffff90000151000a , *ap=0
    shift   str 0xffff90000151000a '' <- 0xffff90000151000b '--env=AA=aa'
  ap = 0xffff90000151000a --env=AA=aa, *ap=45
    make app_cmdline valid pointer to '\0' ap=0xffff90000151000a '--env=AA=aa', 
app_cmdline=0x146e180 ''
  ap0 = 0xffff900001510000 '--verbose', apE = 0xffff90000151000a '--env=AA=aa', 
ntoken = 2, app_cmdline=0xffff900001510015 ''
  argv[0] = 0xffff900001510000 --verbose
  argv[1] = 0xffff90000151000a --env=AA=aa
  ntoken = 2, ii = 2
4 CPUs detected

Input str was "--verbose " + " --env=AA=aa"
After second stresp (e.g second iteration of outer while loop), both spaces 
were replaced with '\0', ap=="\0", and str==ap+1 pointed to "--env=AA=aa".
I want str moved left by one, to overwrite '\0' at ap location.
I hope debug printf makes this clearer.
I will abuse the question to justify that debug code should be left :)


Justin Cinkelj (6):
  libc: add stresep.c file
  include stresep function
  command line: add loader_parse_cmdline with tests
  command line: use loader_parse_cmdline
  command line: add tests for empty commandline string parsing
  command line: check for empty cmdline case after parsing cmdline

 Makefile                |   1 +
 arch/x64/boot.S         |   4 +-
 core/commands.cc        | 146 ++++++++++++++++++++++----
 include/api/string.h    |   1 +
 include/osv/commands.hh |   6 +-
 libc/string/stresep.c   |  87 ++++++++++++++++
 loader.cc               |  55 ++++------
 tests/tst-commands.cc   | 268 ++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 510 insertions(+), 58 deletions(-)
 create mode 100644 libc/string/stresep.c

-- 
2.9.5

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to