Message ID | 20230109001543.vpk6khjtqkjtrjox@tarta.nabijaczleweli.xyz (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Herbert Xu |
Headers | show |
Series | [v2] alias: fix name quoting in printalias | expand |
On 09/01/2023 00:15, наб wrote: > single_quote() over-writes the stack string, so just output the name > separately first. > > Fixes: commit 4ec545e8dc98a3f461cf56bed03adafa81c64aec ("alias: Quote > name in printalias") > --- > really not my year sorry This one works, thanks. I'm wondering if we can save on code size by storing aliases differently instead, allowing for a simpler fix here. If we store aliases in memory in name=value form in a single block of memory, we only need a single savestr() when creating the alias, we only need a single single_quote() call here, we only need a single free() when we're done with the alias, and may be able to share some code with src/var.c for checking the alias name and stopping at the '='. That'd be a larger change though, and even if it is possible, I am not sure it's worth it. Cheers, Harald van Dijk
On Mon, Jan 09, 2023 at 01:15:43AM +0100, наб wrote: > single_quote() over-writes the stack string, so just output the name > separately first. > > Fixes: commit 4ec545e8dc98a3f461cf56bed03adafa81c64aec ("alias: Quote > name in printalias") > --- > really not my year sorry > > src/alias.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) Patch applied. Thanks.
On 09/01/2023 00:30, Harald van Dijk wrote: > On 09/01/2023 00:15, наб wrote: >> single_quote() over-writes the stack string, so just output the name >> separately first. >> >> Fixes: commit 4ec545e8dc98a3f461cf56bed03adafa81c64aec ("alias: Quote >> name in printalias") >> --- >> really not my year sorry > > This one works, thanks. > > I'm wondering if we can save on code size by storing aliases differently > instead, allowing for a simpler fix here. If we store aliases in memory > in name=value form in a single block of memory, we only need a single > savestr() when creating the alias, we only need a single single_quote() > call here, we only need a single free() when we're done with the alias, > and may be able to share some code with src/var.c for checking the alias > name and stopping at the '='. > > That'd be a larger change though, and even if it is possible, I am not > sure it's worth it. Having implemented this, I am also seeing that this does achieve the result of reducing code size. The only visible change is that given e.g. alias foo=bar alias foo we get 'foo=bar' rather than 'foo'='bar' which should be equally acceptable. If there is interest in having this in dash, can adapt and submit it. > Cheers, > Harald van Dijk
On Wed, Jan 11, 2023 at 12:06:04AM +0000, Harald van Dijk wrote: > > If there is interest in having this in dash, can adapt and submit it. Yes please send it to the list. Thanks,
diff --git a/src/alias.c b/src/alias.c index 1375cdd..fcad43b 100644 --- a/src/alias.c +++ b/src/alias.c @@ -197,7 +197,8 @@ freealias(struct alias *ap) { void printalias(const struct alias *ap) { - out1fmt("%s=%s\n", single_quote(ap->name), single_quote(ap->val)); + out1str(single_quote(ap->name)); + out1fmt("=%s\n", single_quote(ap->val)); } STATIC struct alias **