[ob] Remove initializations of memset'd structure
Elena Zannoni
ezannoni@redhat.com
Tue Feb 17 19:37:00 GMT 2004
Eli Zaretskii writes:
> > From: Elena Zannoni <ezannoni@redhat.com>
> > Date: Tue, 17 Feb 2004 09:30:06 -0500
> > > >
> > > > - MSYMBOL_TYPE (m) = mst_unknown;
> > >
> > > This part of the patch seems to assume that mst_unknown has the value
> > > zero. Should we have such assumptions in the code?
> >
> > Yes, in symtab.h mst_unknown is 0.
>
> I know that, I looked it up in symtab.h. The question is, should the
> code rely on the fact that zeroing out the struct causes the
> MSYMBOL_TYPE member to become mst_unknown. Suppose we change the
> enumeration some day, that would break the code.
>
Oh, I see. I misunderstood you.
> So I think a comment is not enough, we should leave that line alone.
> In general, it is my opinion that code should not assume anything
> about the numerical values of enumerated types.
That's true. It would be safer to leave the line alone. I'll change
it back. Also language_unknown is used similarly.
I've committed this.
2004-02-17 Elena Zannoni <ezannoni@redhat.com>
* objfiles.c (terminate_minimal_symbol_table): Add back
initialization of MSYMBOL_TYPE.
Index: objfiles.c
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.c,v
retrieving revision 1.50
diff -u -p -r1.50 objfiles.c
--- objfiles.c 16 Feb 2004 21:14:24 -0000 1.50
+++ objfiles.c 17 Feb 2004 19:36:28 -0000
@@ -283,6 +283,8 @@ terminate_minimal_symbol_table (struct o
= &objfile->msymbols[objfile->minimal_symbol_count];
memset (m, 0, sizeof (*m));
+ /* Don't rely on these enumeration values being 0's. */
+ MSYMBOL_TYPE (m) = mst_unknown;
SYMBOL_INIT_LANGUAGE_SPECIFIC (m, language_unknown);
}
}
More information about the Gdb-patches
mailing list