This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: suggested compile warnings


On Fri, 23 May 2003 16:15:56 -0400, Andrew Cagney <ac131313@redhat.com> said:

> -Wwrite-strings
> It's just hard and really messy.  People occasionally chip away at the
> edges.  Last time I tried, I came across what appeared to be an
> effective xfree("string"), outch!

I've looked at this one fairly seriously.  From my point of view, the
main root issue here is that decode_line_1 takes a char ** instead of
a const char **.  I plan/hope to fix this eventually; I won't get
around to it for a while.

The xfree issue is an interesting one, and I agree that it's another
root problem.  My attitude is actually that xfree should take a const
void * instead of just a void *.  Basically, it seems to me that being
writeable and beeing freeable are orthogonal; examples are:

* Not writeable or freeable: literal

* Writeable and freeable: memory allocated via xmalloc.

* Writeable but not freeable: memory allocated on an obstack.

* Not writeable but freeable: memory that was originally allocated via
  xmalloc but whose contents you don't want to change.  (E.g. a name
  shared among many users, or used as a search key, or something.)

You can argue about examples in the fourth category (maybe their
existence is less clear to C programmers than to C++ programmers,
because of the different idioms for using const in the two languages)
but the third category is real.

Anyways, we can argue about this more once I've fixed decode_line_1.
If anybody else wants to fix it, the easiest thing to do is to write a
wrapper for decode_line_1 whose first argument is "const char
**argptr"; then make a copy of *argptr via alloca, and pass its
address to decode_line_1; then, before returning whatever
decode_line_1 returns, make sure that you modify *argptr in the same
way that decode_line_1 modified *copy_of_argptr.  And then go and fix
all the callers of decode_line_1 to call this new wrapper instead,
passing it a const char **.  (You might get annoyed by the fact that C
doesn't let you automatically convert a char ** into a const char **.)

Once that's happened, then we can argue about xfree; and once _that's_
been changed, then just pick a random char * somewhere (my favorite
would be the 'name' member of struct generic_symbol_info), change it
to a const char *, and follow through a huge chain of updates.

David Carlton
carlton@math.stanford.edu


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]