This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc 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: [PATCH] Small fix for misc/sys/syslog.h


[Ulrich Drepper]
> The opposite is equally true.  If this is about removing one type of
> warning the change is not useful since it simply substitutes it for
> other warnings.

Isn't this about removing a bogus warning from a header file
construct, and replacing it with a real warning about using const
strings without flagging them as const.  Given this code example:

  #define SYSLOG_NAMES
  #include <sys/syslog.h>

  void str_user(char *s) {
    /* ... */
  }

  int main(int argc, char *argv[]) {
    /* ... */
    str_user(priority_names[1].c_name);
    /* ... */
  }

The string passed to str_user() are most likely placed in a read only
memory segment, and trying to write to it will kill the program.  Why
shouldn't this string be flagged 'const' and the programmer warned
that this string is read-only?

My point is that storing a const string into 'char*' in <sys/syslog.h>
give a bogus warning outside the programmers control.  It could be
argued that this isn't really bogus, it is just warning that any later
use of this string should treat it as 'const' as it is read-only.
Changing the type of c_name to 'const char*' move the warning from the
header file and to the point in the code where the string is used, and
where the programmer need to take measures to make sure the string is
used as a read-only string.  How can this be a bad thing.

My point is that the string _is_ read only, and the programmers should
be made aware of the fact with warnings in the code where it is used
as a non-const string.


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