On Sun, 3 Apr 2016, Pedro Giffuni wrote:
On 04/03/16 11:58, Kevin Lo wrote:
On Sun, Apr 03, 2016 at 04:25:51PM +0000, Pedro F. Giffuni wrote:
Log:
g_sched_destroy(): prevent return of uninitialized scalar variable.
For the !gsp case there some chance of returning an uninitialized
return value. Prevent that from happening by initializing the
error value.
Hmm, wouldn't it be better to initialize 'error' before use?
No. The if case initializes error on line 1278, the only problem
is the else case.
Indeed.
Index: sys/geom/sched/g_sched.c
===================================================================
--- sys/geom/sched/g_sched.c (revision 297527)
+++ sys/geom/sched/g_sched.c (working copy)
@@ -1236,7 +1236,7 @@ g_sched_destroy(struct g_geom *gp, boolean_t force
struct g_provider *pp, *oldpp = NULL;
struct g_sched_softc *sc;
struct g_gsched *gsp;
- int error;
+ int error = 0;
g_topology_assert();
sc = gp->softc;
Even when this is frequent, it is against style(9).
style(9) itself was broken to not FORBID initializing variables in
declarations.
The style bug is frequent for "fixing" -Wuninitialised warnings -- the
code had an obscure flow of control that is too hard for compilers and
humans to understand, and the "fix" is to make it even harder to
understand by initializing the variable to a value that is probably
wrong if it is ever used.
It would be better to do the reverse and initialize variables
immediately before use and kill them after their use so that their
lifetime is clear without a deep analysis, but the kill operations
would take large code and isn't in C. You can approximate it using
neted declarations, but I don't like that and style(9) forbids it.
You can approximate it by a macro kill() that might expand to assigning
a NaN to the variables. Compilers would probably object to this macro
if it actually assigns a NaN.
Bruce
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"