提交 70d9c303 编写于 作者: R Rich Felker

remove hack in syslog.h that resulted in aliasing violations

this issue affected the prioritynames and facilitynames arrays which
are only provided when requested (usually by syslogd implementations)
and which are presently defined as compound literals. the aliasing
violation seems to have been introduced as a workaround for bad
behavior by gcc's -Wwrite-strings option, but it caused compilers to
completely optimize out the contents of prioritynames and
facilitynames since, under many usage cases, the aliasing rules prove
that the contents are never accessed.
上级 4ad3588c
...@@ -69,21 +69,17 @@ void vsyslog (int, const char *, va_list); ...@@ -69,21 +69,17 @@ void vsyslog (int, const char *, va_list);
#if defined(SYSLOG_NAMES) #if defined(SYSLOG_NAMES)
#define INTERNAL_NOPRI 0x10 #define INTERNAL_NOPRI 0x10
#define INTERNAL_MARK (LOG_NFACILITIES<<3) #define INTERNAL_MARK (LOG_NFACILITIES<<3)
struct __CODE {
const char *c_name;
int c_val;
};
typedef struct { typedef struct {
char *c_name; char *c_name;
int c_val; int c_val;
} CODE; } CODE;
#define prioritynames ((CODE *)(const struct __CODE []){ \ #define prioritynames ((CODE *)(const CODE []){ \
{ "alert", LOG_ALERT }, { "crit", LOG_CRIT }, { "debug", LOG_DEBUG }, \ { "alert", LOG_ALERT }, { "crit", LOG_CRIT }, { "debug", LOG_DEBUG }, \
{ "emerg", LOG_EMERG }, { "err", LOG_ERR }, { "error", LOG_ERR }, \ { "emerg", LOG_EMERG }, { "err", LOG_ERR }, { "error", LOG_ERR }, \
{ "info", LOG_INFO }, { "none", INTERNAL_NOPRI }, \ { "info", LOG_INFO }, { "none", INTERNAL_NOPRI }, \
{ "notice", LOG_NOTICE }, { "panic", LOG_EMERG }, \ { "notice", LOG_NOTICE }, { "panic", LOG_EMERG }, \
{ "warn", LOG_WARNING }, { "warning", LOG_WARNING }, { 0, -1 } }) { "warn", LOG_WARNING }, { "warning", LOG_WARNING }, { 0, -1 } })
#define facilitynames ((CODE *)(const struct __CODE []){ \ #define facilitynames ((CODE *)(const CODE []){ \
{ "auth", LOG_AUTH }, { "authpriv", LOG_AUTHPRIV }, \ { "auth", LOG_AUTH }, { "authpriv", LOG_AUTHPRIV }, \
{ "cron", LOG_CRON }, { "daemon", LOG_DAEMON }, { "ftp", LOG_FTP }, \ { "cron", LOG_CRON }, { "daemon", LOG_DAEMON }, { "ftp", LOG_FTP }, \
{ "kern", LOG_KERN }, { "lpr", LOG_LPR }, { "mail", LOG_MAIL }, \ { "kern", LOG_KERN }, { "lpr", LOG_LPR }, { "mail", LOG_MAIL }, \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册