Code cleanup
A message that is not in the archive (sent off-list or not yet received): [email protected]
Ian Kent
maintainerQuoted 3 lines · Daniel Richard G.
Hello hello,
First off, is there a public CVS/SVN repository for autofs?
There is a CVS repo but I'm going to stop updating it soon. Use the git repo under http://www.kernel.org/git/
Quoted 3 lines
I grabbed the -rc1 tarball, figured I'd try building it with my usual devel CFLAGS, and... wow. This code's got _issues_, maaan....
Nasty young man!
So you've forced me to go through the cleanup exercise. Had to be done sooner or later anyway.
Quoted 10 lines
See the attached omnibus patch. Commentary follows, in patch order (more or less). Of course, not all these changes need to go in as-is, but they should at least bring attention to some spots that could really use it.
(various files):
* Don't use "#if
WITH_FOO", as this produces a warning ifWITH_FOOis undefined. Use "#ifdef".
Oops.
Quoted 6 lines
daemon/automount.c:* 'mc' is used many times as a local variable in this file; rename the global instance to 'mrc' to avoid gratuitous shadowing
Quoted 7 lines
* 'mrc' (nee 'mc') is not needed outside of this file; declare as static
* Two fields in struct
master_readmap_condwere not specified in the initializer for 'mrc' (nee 'mc')* 'sc' is used many times as a local variable in this file; rename the global instance to 'suc' to avoid gratuitous shadowing
Yep. Ugly fixed.
Quoted 5 lines
include/automount.h:* Disable the OpenBSD
syslog.h#include with a cpp conditional, not a comment. This is a bit safer.
Not relevant, that stuffs going, actually nearly gone.
Quoted 10 lines
* The "extern struct
master_readmap_condmc" declaration is not used
include/lookup_ldap.h:* Added appropriate
WITH_KERBEROSandWITH_SASLcpp conditionals, to avoid breakage when the respective libraries are not used.(Note:
WITH_KERBEROSis a new conditional; support for it needs to be added to the configure script)
Don't think I'll do this.
The SASL code is dependent on the Kerberos stuff so I really need to make the SASL conditional on it. But currently there aren't any checks for the Kerberos libs in configure.in so this will have to be done a bit later.
Quoted 2 lines
* Comment the #endifs if the opening #ifdef is far away
I don't like to do this.
Quoted 4 lines
include/state.h:* Removed a superfluous comma
Oops.
Quoted 7 lines
lib/cache.c:* Eliminated "implicit cast to unsigned type" warnings
lib/cat_path.c:
Quoted 7 lines
* Tweaked the
_strlen()function: Eliminated the unnecessary de-consting cast, and rewrote the logic w.r.t. 'max' (this is unsigned, therefore the max<0 check is pointless; it's not nice to modify your arguments; pointer arithmetic sucks)
P.S.:_strlen()should really have a return type ofsize_t, but I didn't care enough to change this.
Now this was a good catch.
Fixed.
Quoted 4 lines
lib/master.c:* Eliminated a stray semicolon
Oops.
Quoted 8 lines
* Straightened out some unnecessary variable const-ness
lib/master_parse.y:* #define
YYENABLE_NLSandYYLTYPE_IS_TRIVIALto zero; #ifdefs with these appear in the generated code, and you get warnings if they are not defined
Yep and there were similar issues with the Flex modules. Fixed.
Quoted 5 lines
lib/mounts.c:*
m_devandm_inoare 'long unsigned int' values, so cast them to avoidsscanf()format warnings
Fixed.
Quoted 4 lines
lib/nss_parse.y:* Same deal with
YYENABLE_NLSandYYLTYPE_IS_TRIVIAL
Ditto above.
Quoted 2 lines
* Aaaarg! C++ comments in C code! Kill 'em! Kill 'em!
Cleaned and sanitized.
Quoted 5 lines
lib/rpc_subs.c:* You don't want to use a local variable named '
h_errno'.
Quoted 8 lines
fusion:/tmp$ grep h_errno /usr/include/netdb.h We use a macro to access always the thread-specific `h_errno' variable. */ #define h_errno (*__h_errno_location ()) ...(There were some places that used
h_errnowithout declaring it locally. I'm assuming that nowhere was this meant to refer to the globalnetdb.hh_errnovariable.)
Double oops, another good catch.
Fixed.
Quoted 11 lines
modules/lookup_file.c:modules/lookup_hosts.c* What first caught my attention here was a warning that
me->mapentis being passed in as a format string tosprintf()without further arguments (lots of fun if there's a "%s" in there somewhere), but that line and the one before seemed a bit bizarrely written to me. (You callstrlen()on a string, then usesprintf()as an unsafestrcpy()replacement, and grab the return value to get the length of that same string??) Replaced with something more straightforward.
Hehe, cleaned.
Quoted 5 lines
lookup_ldap.c:* What the heck is '?:' supposed to return if the expression is true? (Not valid C90, at any rate)
Ya well, I changed it.
Quoted 3 lines
* My OpenLDAP 2.1.30 header does not define
LDAP_SCOPE_ONE. It does, however, defineLDAP_SCOPE_ONELEVEL.
OK. caught me on that.
Fixed.
Quoted 4 lines
* 'struct mapent me' is unused
* More mapent/mapent_len silliness
And fixed and cleaned.
Quoted 4 lines
modules/mount_nfs.c:* This looks like a bug to me. Does it look like a bug to you?
Definitely, and found another during the process.
Fixed.
Quoted 9 lines
modules/replicated.c:* You don't want to use a local variable named
h_addr, either.fusion:/tmp$ grep h_addr /usr/include/netdb.h int h_addrtype; /* Host address type. */ char **h_addr_list; /* List of addresses from name server. */ #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
Aggh .. caught me again, yet another good catch.
Fixed.
Quoted 5 lines
There's still a ton of warnings, mostly of variables shadowing other variables, but those affect code clarity more so than correctness.
I'm not quite finished the cleanup yet but clone the repo and have another go at it.
Ian