Re: [hackers] [PATCH][sbase] paste: Allow null delim
Hi Richard,
Thanks for the patch. Can you clarify if this change fixes `-d "\0"`,
`-d ""` or `-d""`?
Looking at POSIX, I see that `-d '\0'` must be supported, `-d ""` is
unspecified, and `-d""` is invalid, since paste(1) must follow the
utility syntax guidelines (guideline 7).
I recently investigated a similar issue to this in tr(1). I think a
proper solution would be to add length parameters to utflen and
utftorunestr so that they can handle 0-bytes in the strings.
On 2020-03-02, Richard Ipsum <richardipsum_AT_vx21.xyz> wrote:
> ---
> paste.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/paste.c b/paste.c
> index b0ac761..0159fe0 100644
> --- a/paste.c
> +++ b/paste.c
> _AT_@ -53,7 +53,8 @@ nextline:
>
> for (; efgetrune(&c, dsc[i].fp, dsc[i].name) ;) {
> for (m = last + 1; m < i; m++)
> - efputrune(&(delim[m % delimlen]), stdout, "<stdout>");
> + if (delim[m % delimlen] != '\0')
> + efputrune(&(delim[m % delimlen]), stdout, "<stdout>");
> last = i;
> if (c == '\n') {
> if (i != fdescrlen - 1)
> _AT_@ -68,7 +69,8 @@ nextline:
> if (i == fdescrlen - 1)
> putchar('\n');
> else
> - efputrune(&d, stdout, "<stdout>");
> + if (d != '\0')
> + efputrune(&d, stdout, "<stdout>");
> last++;
> }
> }
> _AT_@ -96,7 +98,7 @@ main(int argc, char *argv[])
> seq = 1;
> break;
> case 'd':
> - adelim = EARGF(usage());
> + adelim = ARGF();
I think allowing missing option-argument here breaks POSIX compatibility.
> unescape(adelim);
> break;
> default:
> _AT_@ -109,8 +111,12 @@ main(int argc, char *argv[])
> /* populate delimiters */
> /* TODO: fix libutf to accept sizes */
> delim = ereallocarray(NULL, utflen(adelim) + 1, sizeof(*delim));
> - if (!(delimlen = utftorunestr(adelim, delim)))
> + if (*adelim == '\0') {
> + delimlen = 1;
> + *delim = '\0';
> + } else if (!(delimlen = utftorunestr(adelim, delim))) {
> usage();
> + }
>
> /* populate file list */
> dsc = ereallocarray(NULL, argc, sizeof(*dsc));
> --
> 2.25.1
Received on Thu Mar 05 2020 - 09:33:33 CET
This archive was generated by hypermail 2.3.0
: Thu Mar 05 2020 - 09:36:38 CET