I've been reading fdcopy.c. main() checks "if (argc < 1) usage();". That's unlikely to ever be true since progname is argv[0] so argc is always at least 1. It should be argc < 2 to check that no arguments have been given.
Speaking of progname, it doesn't skip over any directories so diagnostics will include the full path of the executable. One way is: (progname = strrchr(*argv, '/')) ? progname++ : (progname = *argv);
parse_number is checking errno after strtoul() but that's strictly incorrect AIUI. It isn't enough to zero errno before the call, errno's value should only be checked after strtoul() has returned ULONG_MAX to indicate there's a problem. parse_number is also happy to handle a negative, it may be better to trap that earlier rather than let it pass further through the code.
Comment #1
Posted on Jul 15, 2009 by Happy RhinoGood catch re: argc, i'll send a patch in a few to fix that.
Re: the full path of progname, i understand your point, i think progname = basename(argv[0]); is a simpler way of achieving it though.
Re: strtoul() & error checking, according to strtoul(3) on linux:
Since strtoul() can legitimately return 0 or LONG_MAX (LLONG_MAX for
strtoull()) on both success and failure, the calling program should set errno to 0 before the call, and then determine if an error occurred by checking whether errno has a nonzero value after the call.
so if i'm reading that correctly, then the current behavior should be fine.
Thanks for the comments
Comment #2
Posted on Jul 20, 2009 by Happy Rhino(No comment was entered for this change.)
Status: Fixed
Labels:
Type-Defect
Priority-Medium