Re: multidefine segfault

2017-04-11 Thread Laurent Bercot

Is it possible to use one multidefine on a $line that gets an unknown
number of words from stdin, then split it by one type of delimiter
with the -r option (not knowing how many words it would get into
$val). For instance, val might contain an unknown number of words.

Then, I'd like to use a second multidefine or something like it to
extract those words out of $val into separate variables. Is this
possible?


 Forget about using a second multidefine, this is likely not what you 
want.

 "multidefine -r" splits the value it reads:
 "multidefine -r $line { val }" would susbstitute $val with as many 
words

as there are in $line. This is convenient when you want to read all the
words in $line, but not when you need to extract some of the words.

 multidefine is meant to provide equivalent functionality to the shell's
"read" command. Just like "read", it's good when you know the format of
your lines in advance; not so much with a variable format. If you need
to extract information from a variable format, I'd advise you to
process your line with standard utilities such as "cut", for instance.

 IF you want more precise help, you'll have to say exactly what you're
trying to accomplish, because it's not clear to me that your design is
sound.

--
 Laurent



Re: multidefine segfault

2017-04-11 Thread fff iii
>  You only need one invocation.
>
> pipeline { echo one two three }
> withstdinas -n line
> importas -u line line
> multidefine $line { cmd key val }
> echo $key $val
>
>  will print "two three".

Thanks.

Is it possible to use one multidefine on a $line that gets an unknown
number of words from stdin, then split it by one type of delimiter
with the -r option (not knowing how many words it would get into
$val). For instance, val might contain an unknown number of words.

Then, I'd like to use a second multidefine or something like it to
extract those words out of $val into separate variables. Is this
possible?

Thank you.


Re: multidefine segfault

2017-04-11 Thread Laurent Bercot

Out of curiousity, what kind of bug was it in terms of what was
happening to the memory?


 Out of bounds access. The -r option code does "array[i-1]", and i may 
be

zero when the key block is empty, which should never happen but was not
properly checked. So your use case triggered "array[(unsigned int)-1]",
which hits a place in memory it definitely should not. :)



Also, in the above example, I would like to feed a three word input
(string or line in regular terminology?) to the first multidefine, and
extract the two of the words out of $msg with the second multidefine,
but it gives me an unquoted argument error. What am I doing wrong, or
what's the correct way to do this? I am stuck...


 You only need one invocation.

pipeline { echo one two three }
withstdinas -n line
importas -u line line
multidefine $line { cmd key val }
echo $key $val

 will print "two three".

--
 Laurent



Re: multidefine segfault

2017-04-11 Thread fff iii
Thanks Laurent!

Out of curiousity, what kind of bug was it in terms of what was
happening to the memory?

Also, in the above example, I would like to feed a three word input
(string or line in regular terminology?) to the first multidefine, and
extract the two of the words out of $msg with the second multidefine,
but it gives me an unquoted argument error. What am I doing wrong, or
what's the correct way to do this? I am stuck...

I don't care to be credited for bug reports, but thank you.

Thank you for the execline, it's really great!


Re: multidefine segfault

2017-04-11 Thread Laurent Bercot

It's the second multidefine segfaulting. It does not seem to happen
without '-r'.


 Thanks for the report! Should be fixed in the latest git, please try.

 You should get an error message saying "empty block" instead of a
segfault. Your script is a misuse of multidefine ("$msg" expands to
two words, so the second invocation of multidefine doesn't understand
what's going on), but that misuse wasn't properly caught.

 Please give me a name (real if possible, else nickname) and e-mail 
address

you wish to be credited with for the bug-report.

--
 Laurent



Re: multidefine segfault

2017-04-10 Thread fff iii
'multidefine' segfaults on a recent OpenBSD snapshot:

The execline script like :

#!/usr/local/bin/execlineb -W

withstdinas line
importas -u line line
multidefine -r  $line  { cmd msg }
multidefine -r $msg { key val }

$ echo ' test ' | ./testmult
Segmentation fault (core dumped)

It's the second multidefine segfaulting. It does not seem to happen
without '-r'.


Thank you.