anuml / neatx

Automatically exported from code.google.com/p/neatx
0 stars 0 forks source link

Source code of fdcopy.c #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by ralph.co...@gmail.com on 14 Jul 2009 at 9:28

GoogleCodeExporter commented 8 years ago
Good 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

Original comment by kormat on 15 Jul 2009 at 6:38

GoogleCodeExporter commented 8 years ago

Original comment by kormat on 20 Jul 2009 at 5:26