diff mbox

fix "Illegal number" on FreeBSD & macOS for x=; echo $((x))

Message ID a4f5a2d5-11fa-fef6-23bf-c1b7e0add520@inlv.org (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

Martijn Dekker March 6, 2018, 2:49 p.m. UTC
I had totally forgotten this bug had come up before in January 2017:

https://www.spinics.net/lists/dash/msg01271.html

The original reporter, Michael Greenberg, didn't specify the bug only
occurs on macOS and FreeBSD but it does seem to be the same bug.

He submitted a different patch to fix it:


- M.
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Martijn Dekker March 6, 2018, 5:16 p.m. UTC | #1
Op 06-03-18 om 14:49 schreef Martijn Dekker:
> The original reporter, Michael Greenberg, didn't specify the bug only
> occurs on macOS and FreeBSD but it does seem to be the same bug.
> 
> He submitted a different patch to fix it:
[snip]
> Which is better?

That other patch only fixes it for the unset case, not for the empty
case, so I think the recent one is better.

- M.
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Herbert Xu March 7, 2018, 6:27 a.m. UTC | #2
Martijn Dekker <martijn@inlv.org> wrote:
> Op 06-03-18 om 14:49 schreef Martijn Dekker:
>> The original reporter, Michael Greenberg, didn't specify the bug only
>> occurs on macOS and FreeBSD but it does seem to be the same bug.
>> 
>> He submitted a different patch to fix it:
> [snip]
>> Which is better?
> 
> That other patch only fixes it for the unset case, not for the empty
> case, so I think the recent one is better.

Yes, yours is better but please resend it with the ERANGE change
as suggested.

Thanks,
diff mbox

Patch

diff --git a/src/var.c b/src/var.c
index cc6f7f2..e34f9cf 100644
--- a/src/var.c
+++ b/src/var.c
@@ -353,7 +353,7 @@  lookupvar(const char *name)

 intmax_t lookupvarint(const char *name)
 {
-	return atomax(lookupvar(name) ?: nullstr, 0);
+	return atomax(lookupvar(name) ?: "0", 0);
 }

Which is better?