[Toybox] [PATCH] factor shouldn't give incorrect answers for >64-bit integers.

2017-05-13 Thread enh
---
 toys/other/factor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
From fab8f56370abe41374692587c4bf92bdbd8b711a Mon Sep 17 00:00:00 2001
From: Elliott Hughes 
Date: Sat, 13 May 2017 12:48:35 -0700
Subject: [PATCH] factor shouldn't give incorrect answers for >64-bit integers.

---
 toys/other/factor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/toys/other/factor.c b/toys/other/factor.c
index 0e07d71..f0e69c5 100644
--- a/toys/other/factor.c
+++ b/toys/other/factor.c
@@ -29,8 +29,9 @@ static void factor(char *s)
 if (*s=='-') dash = *s++;
 if (!*s) return;
 
+errno = 0;
 l = strtoull(s, , 0);
-if (*s && !isspace(*s)) {
+if (errno || (*s && !isspace(*s))) {
   error_msg("%s: not integer", err);
   while (*s && !isspace(*s)) s++;
   continue;
-- 
2.13.0.rc2.291.g57267f2277-goog

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] Fix various seq bugs.

2017-05-13 Thread enh
i wasn't seriously considering implementing the arbitrary-precision
arithmetic that GNU seems to use, but i did wonder about at least
using long long instead of double for 53 wrote:
> Use the precision of the inputs to determine the default output. This was the
> reported bug. (Two existing tests were failing on the host because of this,
> so I've fixed those tests and added more tests for other special cases.)
>
> Reject invalid inputs.
>
> Match GNU/busybox behavior with 0 increment. (An existing test was failing on
> the host because of this.)
>
> Also remove a couple of locals that were duplicating globals.
>
> Bug: http://b/37792952
> ---
>  tests/seq.test | 23 +++---
>  toys/lsb/seq.c | 74 
> ++
>  2 files changed, 69 insertions(+), 28 deletions(-)



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [PATCH] Fix various seq bugs.

2017-05-13 Thread enh
Use the precision of the inputs to determine the default output. This was the
reported bug. (Two existing tests were failing on the host because of this,
so I've fixed those tests and added more tests for other special cases.)

Reject invalid inputs.

Match GNU/busybox behavior with 0 increment. (An existing test was failing on
the host because of this.)

Also remove a couple of locals that were duplicating globals.

Bug: http://b/37792952
---
 tests/seq.test | 23 +++---
 toys/lsb/seq.c | 74 ++
 2 files changed, 69 insertions(+), 28 deletions(-)
From d1112d0eb4d45b3f2e592e058a433fbe2484e63f Mon Sep 17 00:00:00 2001
From: Elliott Hughes 
Date: Sat, 13 May 2017 12:29:24 -0700
Subject: [PATCH] Fix various seq bugs.

Use the precision of the inputs to determine the default output. This was the
reported bug. (Two existing tests were failing on the host because of this,
so I've fixed those tests and added more tests for other special cases.)

Reject invalid inputs.

Match GNU/busybox behavior with 0 increment. (An existing test was failing on
the host because of this.)

Also remove a couple of locals that were duplicating globals.

Bug: http://b/37792952
---
 tests/seq.test | 23 +++---
 toys/lsb/seq.c | 74 ++
 2 files changed, 69 insertions(+), 28 deletions(-)

diff --git a/tests/seq.test b/tests/seq.test
index 7107978..a7b8068 100755
--- a/tests/seq.test
+++ b/tests/seq.test
@@ -19,9 +19,11 @@ testing "count up by 2" "seq 4 2 8" "4\n6\n8\n" "" ""
 testing "count down by 2" "seq 8 -2 4" "8\n6\n4\n" "" ""
 testing "count wrong way #1" "seq 4 -2 8" "" "" ""
 testing "count wrong way #2" "seq 8 2 4" "" "" ""
-testing "count by .3" "seq 3 .3 4" "3\n3.3\n3.6\n3.9\n" "" ""
-testing "count by -.9" "seq .7 -.9 -2.2" "0.7\n-0.2\n-1.1\n-2\n" "" ""
-testing "count by zero" "seq 4 0 8 | head -n 10" "" "" ""
+testing "count by .3" "seq 3 .3 4" "3.0\n3.3\n3.6\n3.9\n" "" ""
+testing "count by -.9" "seq .7 -.9 -2.2" "0.7\n-0.2\n-1.1\n-2.0\n" "" ""
+testing "count up by zero" "seq 4 0 8 | head -n 4" "4\n4\n4\n4\n" "" ""
+testing "count nowhere by zero" "seq 4 0 4 | head -n 4" "4\n4\n4\n4\n" "" ""
+testing "count down by zero" "seq 8 0 4 | head -n 4" "" "" ""
 testing "separator -" "seq -s - 1 3" "1-2-3\n" "" ""
 testing "format string" 'seq -f %+01g -10 5 10' "-10\n-5\n+0\n+5\n+10\n" \
   "" ""
@@ -46,3 +48,18 @@ do
   testing "filter reject -f '$i'" \
 "seq -f '$i' 1 3 2>/dev/null || echo no" "no\n" "" ""
 done
+
+testing "precision inc" "seq -s, 1.0 2.00 4" "1.00,3.00\n" "" ""
+testing "precision first" "seq -s, 1.000 2.0 4" "1.000,3.000\n" "" ""
+testing "precision last" "seq -s, 1.0 2.0 4.00" "1.0,3.0\n" "" ""
+testing "precision int" "seq -s, 9007199254740991 1 9007199254740991" \
+  "9007199254740991\n" "" ""
+testing "precision e" "seq -s, 1.0e0 2" "1.0,2.0\n" "" ""
+testing "precision E" "seq -s, 1.0E0 2" "1.0,2.0\n" "" ""
+
+testing "invalid last" "seq 1 1 1f 2>/dev/null || echo y" "y\n" "" ""
+testing "invalid first" "seq 1f 1 1 2>/dev/null || echo y" "y\n" "" ""
+testing "invalid increment" "seq 1 1f 1 2>/dev/null || echo y" "y\n" "" ""
+
+# TODO: busybox fails this too, but GNU seems to not use double for large ints.
+#testing "too large for double" "seq -s, 9007199254740991 1 9007199254740992" "9007199254740992\n" "" ""
diff --git a/toys/lsb/seq.c b/toys/lsb/seq.c
index 0202c67..bcf4b74 100644
--- a/toys/lsb/seq.c
+++ b/toys/lsb/seq.c
@@ -15,11 +15,11 @@ config SEQ
 
 Count from first to last, by increment. Omitted arguments default
 to 1. Two arguments are used as first and last. Arguments can be
-negative or floating point.
+positive/negative and integer/floating point.
 
 -f	Use fmt_str as a printf-style floating point format string
 -s	Use sep_str as separator, default is a newline character
--w	Pad to equal width with leading zeroes.
+-w	Pad to equal width with leading zeroes
 */
 
 #define FOR_seq
@@ -42,51 +42,75 @@ static void insanitize(char *f)
   }
 }
 
+// Parse a numeric argument, with error-checking, and setting *prec to the
+// precision of this argument if greater than the existing value.
+static double parsef(char *what, char *s, int *prec)
+{
+  char *dp = strchr(s, '.'), *end;
+  double result;
+
+  if (dp && prec) {
+int this_prec = strlen(dp) - 1;
+char *e = strchr(dp, 'e');
+
+if (!e) e = strchr(dp, 'E');
+if (e) this_prec -= strlen(e);
+if (this_prec > *prec) *prec = this_prec;
+  }
+
+  errno = 0;
+  result = strtod(s, );
+  if (errno || *end) error_exit("invalid %s", what);
+  return result;
+}
+
 void seq_main(void)
 {
-  double first, increment, last, dd;
-  char *sep_str = "\n", *fmt_str = "%g";
-  int i;
+  double first = 1, increment = 1, last, dd;
+  int prec = 0, i;
 
-  // Parse command line arguments, with appropriate defaults.
-  // Note that any non-numeric arguments are 

Re: [Toybox] Valid range for stat userID and groupID?

2017-05-13 Thread darken
Unfortunately the output is from devices I don't have access to, via
automatic (anonymous) bug report.

Am 13.05.2017 19:38 schrieb "Rob Landley" :

> On 05/13/2017 08:29 AM, darken wrote:
> > I stumbled upon the following "stat -c
> > "%a:%F:%d:%i:%u:%g:%s:%B:%b:%Z:%N" output from a GT-N5110@7.1.2
> >
> >> 5665:FIFO (named
> > pipe):45836:456097:1171143868:4160815103:0:512:0:18446744073
> 709551615:`/data/user/0/de.andip71.boeffla_config_v2/app_
> webview/webview_data.lock'
> >
> > The a UID of "1171143868" and GUID of "4160815103" seems way too large.
> > The device in question is rooted and that specific file with sticky &
> > suid bit seems to be a bit special anyways, but I've also seen this from
> > more vanilla files like this from a SM-N9300@6.0.1:
> >
> >> 600:regular
> > file:100d:116024:1001:4294967295:16384:4096:32:1494489310:`/
> data/user/0/com.android.providers.telephony/opname.db'
> >
> > GUID of "4294967295" seems large too.
>
> That's -1 typecast to unsigned int.
>
> Your previous UID and GID are:
>
> 1171143868: 0b010001011100111000001000
> 4160815103: 0b1000
>
> Other than the first 8 bits of the first one being a capital "E" in
> ascii this makes no sense to me.
>
> Try running it under strace to see what stat() is returning?
>
> Rob
>
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] Valid range for stat userID and groupID?

2017-05-13 Thread Rob Landley
On 05/13/2017 08:29 AM, darken wrote:
> I stumbled upon the following "stat -c
> "%a:%F:%d:%i:%u:%g:%s:%B:%b:%Z:%N" output from a GT-N5110@7.1.2
> 
>> 5665:FIFO (named
> pipe):45836:456097:1171143868:4160815103:0:512:0:18446744073709551615:`/data/user/0/de.andip71.boeffla_config_v2/app_webview/webview_data.lock'
> 
> The a UID of "1171143868" and GUID of "4160815103" seems way too large.
> The device in question is rooted and that specific file with sticky &
> suid bit seems to be a bit special anyways, but I've also seen this from
> more vanilla files like this from a SM-N9300@6.0.1:
> 
>> 600:regular
> file:100d:116024:1001:4294967295:16384:4096:32:1494489310:`/data/user/0/com.android.providers.telephony/opname.db'
> 
> GUID of "4294967295" seems large too.

That's -1 typecast to unsigned int.

Your previous UID and GID are:

1171143868: 0b010001011100111000001000
4160815103: 0b1000

Other than the first 8 bits of the first one being a capital "E" in
ascii this makes no sense to me.

Try running it under strace to see what stat() is returning?

Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] Valid range for stat userID and groupID?

2017-05-13 Thread darken
> are you building with bionic? glibc won't know what android does with

I'm building against musl libc. I couldn't get toybox with bionic (though
the last time i tried was a few month ago).

> glibc won't know what android does with uid/gid for apps.

Doesn't bionic/3rd party only make a difference when trying to resolve the
ids to names?

> (also, 4294967295 is -1.)

Hm, -1 is not a valid guid though right? They all have to be positive
ranging from 0 to X?

> i couldn't find any files on a Pixel XL where the built-in toybox
reported unusual uids or gids.

It's not very common, a few files, among a few devices out of thousands.
I never saw this in person either, just the occasional reports.

> as usual, not using Android's libc on an Android device is likely to lead
to confusing results.

I'll look into setting up a bionic toolchain again.
You don't happen to have an edition of "Crosscompiling toybox with bionic
for dummies" at hand :)?

2017-05-13 18:45 GMT+02:00 enh :

> are you building with bionic? glibc won't know what android does with
> uid/gid for apps. (also, 4294967295 is -1.)
>
> i couldn't find any files on a Pixel XL where the built-in toybox
> reported unusual uids or gids.
>
> as usual, not using Android's libc on an Android device is likely to
> lead to confusing results.
>
> On Sat, May 13, 2017 at 6:29 AM, darken  wrote:
> > I stumbled upon the following "stat -c "%a:%F:%d:%i:%u:%g:%s:%B:%b:%
> Z:%N"
> > output from a GT-N5110@7.1.2
> >
> >> 5665:FIFO (named
> >> pipe):45836:456097:1171143868:4160815103:0:512:0:
> 18446744073709551615:`/data/user/0/de.andip71.boeffla_
> config_v2/app_webview/webview_data.lock'
> >
> > The a UID of "1171143868" and GUID of "4160815103" seems way too large.
> The
> > device in question is rooted and that specific file with sticky & suid
> bit
> > seems to be a bit special anyways, but I've also seen this from more
> vanilla
> > files like this from a SM-N9300@6.0.1:
> >
> >> 600:regular
> >> file:100d:116024:1001:4294967295:16384:4096:32:
> 1494489310:`/data/user/0/com.android.providers.telephony/opname.db'
> >
> > GUID of "4294967295" seems large too.
> >
> > Is it normal and I should expect these kind of values or is this some
> weird
> > root related stuff one should ignore or is it maybe a bug in toybox or
> the
> > Android kernel?
> >
> > ~Matthias
> >
> > ___
> > Toybox mailing list
> > Toybox@lists.landley.net
> > http://lists.landley.net/listinfo.cgi/toybox-landley.net
> >
>
>
>
> --
> Elliott Hughes - http://who/enh - http://jessies.org/~enh/
> Android native code/tools questions? Mail me/drop by/add me as a reviewer.
>
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] Valid range for stat userID and groupID?

2017-05-13 Thread enh
are you building with bionic? glibc won't know what android does with
uid/gid for apps. (also, 4294967295 is -1.)

i couldn't find any files on a Pixel XL where the built-in toybox
reported unusual uids or gids.

as usual, not using Android's libc on an Android device is likely to
lead to confusing results.

On Sat, May 13, 2017 at 6:29 AM, darken  wrote:
> I stumbled upon the following "stat -c "%a:%F:%d:%i:%u:%g:%s:%B:%b:%Z:%N"
> output from a GT-N5110@7.1.2
>
>> 5665:FIFO (named
>> pipe):45836:456097:1171143868:4160815103:0:512:0:18446744073709551615:`/data/user/0/de.andip71.boeffla_config_v2/app_webview/webview_data.lock'
>
> The a UID of "1171143868" and GUID of "4160815103" seems way too large. The
> device in question is rooted and that specific file with sticky & suid bit
> seems to be a bit special anyways, but I've also seen this from more vanilla
> files like this from a SM-N9300@6.0.1:
>
>> 600:regular
>> file:100d:116024:1001:4294967295:16384:4096:32:1494489310:`/data/user/0/com.android.providers.telephony/opname.db'
>
> GUID of "4294967295" seems large too.
>
> Is it normal and I should expect these kind of values or is this some weird
> root related stuff one should ignore or is it maybe a bug in toybox or the
> Android kernel?
>
> ~Matthias
>
> ___
> Toybox mailing list
> Toybox@lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] Valid range for stat userID and groupID?

2017-05-13 Thread darken
I stumbled upon the following "stat -c "%a:%F:%d:%i:%u:%g:%s:%B:%b:%Z:%N"
output from a GT-N5110@7.1.2

> 5665:FIFO (named
pipe):45836:456097:1171143868:4160815103:0:512:0:18446744073709551615:`/data/user/0/de.andip71.boeffla_config_v2/app_webview/webview_data.lock'

The a UID of "1171143868" and GUID of "4160815103" seems way too large. The
device in question is rooted and that specific file with sticky & suid bit
seems to be a bit special anyways, but I've also seen this from more
vanilla files like this from a SM-N9300@6.0.1:

> 600:regular
file:100d:116024:1001:4294967295:16384:4096:32:1494489310:`/data/user/0/com.android.providers.telephony/opname.db'

GUID of "4294967295" seems large too.

Is it normal and I should expect these kind of values or is this some weird
root related stuff one should ignore or is it maybe a bug in toybox or the
Android kernel?

~Matthias
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] Stat output for %N

2017-05-13 Thread darken
That was it.
I accidentally called stat by "stat" instead of "/path/to/toybox stat"
which meant on some devices it used a different stat applet (probably
busybox).

2017-05-13 5:25 GMT+02:00 enh :

> the one without the quotes is busybox.
>
> quotes is either GNU or toybox.
>
> On Fri, May 12, 2017 at 7:38 PM, darken  wrote:
> > Using
> >
> >> stat -c "%a:%F:%d:%i:%u:%g:%s:%B:%b:%Z:%N",
> >
> > the output is usually like this:
> >
> >>
> >> 770:directory:24:5546467:0:9997:8192:512:24:1494593733:`/
> storage/emulated/0/Download'
> >
> > but on some devices the output is
> >
> >>
> >> 770:directory:21:260813:10259:1028:4096:512:8:1487106302:/
> storage/emulated/0/Android/data/au.com.shiftyjelly.pocketcasts
> >
> > note the difference in quotes around the filepath. Both items are
> > directories.
> >
> > Why the format difference?
> >
> > ~Matthias
> >
> > ___
> > Toybox mailing list
> > Toybox@lists.landley.net
> > http://lists.landley.net/listinfo.cgi/toybox-landley.net
> >
>
>
>
> --
> Elliott Hughes - http://who/enh - http://jessies.org/~enh/
> Android native code/tools questions? Mail me/drop by/add me as a reviewer.
>
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net