expand_number() for fetch'es -B and -S switches

Alexander Best arundel at freebsd.org
Wed Sep 8 13:43:50 UTC 2010


On Wed Sep  8 10, Dag-Erling Smørgrav wrote:
> Alexander Best <arundel at freebsd.org> writes:
> > Dag-Erling Smørgrav <des at des.no> writes:
> > > Alexander Best <arundel at freebsd.org> writes:
> > > > so how about forgetting about expand_number() and simply
> > > > introducing a maximum buffer size of 1 megabyte?
> > > so how about just leaving the code alone?  :)
> > i thought you wanted to have a maximum buffer size of 1MB in fetch?
> 
> Yes, I was just commenting on the highly roundabout way we followed only
> to end up almost at the status quo.
> 
> > right now -B can be any value and it's quite easy to trigger ENOMEM.
> 
> "don't do that, then!"
> 
> My suggestion is that if you're going to change it at all, use
> expand_number() *and* limit it to 1 MB.

hmmm...i guess it's best to leave it as it is now, because:

1) it's not really worth adding expand_number(), if the limit is 1m. the
   difference between typing '-B 1m' and '-B 1048576' is rather minor.
2) adding a fetch(1) entry, telling the user that in fact he can use '-B 1g',
   but this get's silently reduced to 1m would make things more complicated.

since, as you pointed out, using a buffer > 1m isn't going to improve anything,
there's no point in making it easier for the user to use higher values than
this (i.e. by introducing expand_number()).

sorry for all the hassle. ;)

ps: you might still want to consider adding the attached patch, which makes it
more apparent that the -S switch causes problems.

`fetch -B 10000 -S 145l86` e.g. will output:

"fetch: invalid size (145l86)", however the user might not now which of the
switches caused 'fetch' to fail.

cheers.
alex

> 
> DES
> -- 
> Dag-Erling Smørgrav - des at des.no

-- 
a13x
-------------- next part --------------
diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c
index 7553bd8..852e948 100644
--- a/usr.bin/fetch/fetch.c
+++ b/usr.bin/fetch/fetch.c
@@ -842,7 +842,7 @@ main(int argc, char *argv[])
 		case 'S':
 			S_size = (off_t)strtol(optarg, &end, 10);
 			if (*optarg == '\0' || *end != '\0')
-				errx(1, "invalid size (%s)", optarg);
+				errx(1, "invalid file size (%s)", optarg);
 			break;
 		case 's':
 			s_flag = 1;


More information about the freebsd-hackers mailing list