summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-06-26 07:05:23 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-06-26 07:05:23 +0000
commit10df374d97072a1403c2abc966d6c10d72f3b47a (patch)
tree7d84a57392541f5b32ab2a5db6dbe6bb707850b9
parent561fdaf26ffe064c951b9f34ec1bbec2aba165f5 (diff)
downloadrsyslog-10df374d97072a1403c2abc966d6c10d72f3b47a.tar.gz
rsyslog-10df374d97072a1403c2abc966d6c10d72f3b47a.tar.xz
rsyslog-10df374d97072a1403c2abc966d6c10d72f3b47a.zip
fixed code in iovCreate() that broke C's strict aliasing rules
-rw-r--r--NEWS3
-rw-r--r--syslogd.c25
2 files changed, 20 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index 7094d800..bc48d561 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,9 @@
---------------------------------------------------------------------------
Version 1.14.0 (RGer/Peter Vrabec), 2007-06-??
- Peter Vrabec provided IPv6 for rsyslog, so we are now IPv6 enabled
+-fixed code in iovCreate() that broke C's strict aliasing rules
+- fixed some char/unsigned char differences that forced the compiler
+ to spit out warning messages
---------------------------------------------------------------------------
Version 1.13.5 (RGer), 2007-06-22
- made the TCP session limit configurable via command line switch
diff --git a/syslogd.c b/syslogd.c
index 8432da6c..8197adaf 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -5809,6 +5809,8 @@ void iovCreate(struct filed *f)
struct template *pTpl;
struct templateEntry *pTpe;
struct msg *pMsg;
+ char *pVal; /* This variable must be introduced to keep with strict aliasing rules */
+ size_t iLenVal; /* This variable must be introduced to keep with strict aliasing rules */
assert(f != NULL);
@@ -5828,9 +5830,16 @@ void iovCreate(struct filed *f)
++v;
++iIOVused;
} else if(pTpe->eEntryType == FIELD) {
- v->iov_base = MsgGetProp(pMsg, pTpe, NULL, f->f_bMustBeFreed + iIOVused);
- v->iov_len = strlen(v->iov_base);
- /* TODO: performance optimize - can we obtain the length? */
+ /* Just for the records and because I needed some time to look it up again:
+ * f->f_bMustBeFreed + iIOVused is a pointer to the "must be freed" indicator
+ * for the entry in question. So, yes, we are passing in a pointer and it gets
+ * updated by the called procedures. The address of operator (&) must NOT be used
+ * because it already is a pointer. Actually, f->f_bMustBeFreed is the base address
+ * of an array of unsigned shorts. This array is allocated when the configuration
+ * file is read. rgerhards, 2007-06-26
+ */
+ pVal = MsgGetProp(pMsg, pTpe, NULL, f->f_bMustBeFreed + iIOVused);
+ iLenVal = strlen(pVal);
/* we now need to check if we should use SQL option. In this case,
* we must go over the generated string and escape '\'' characters.
* rgerhards, 2005-09-22: the option values below look somewhat misplaced,
@@ -5838,11 +5847,11 @@ void iovCreate(struct filed *f)
* existing thing).
*/
if(f->f_pTpl->optFormatForSQL == 1)
- doSQLEscape((char**)&v->iov_base, &v->iov_len,
- f->f_bMustBeFreed + iIOVused, 1);
+ doSQLEscape(&pVal, &iLenVal, f->f_bMustBeFreed + iIOVused, 1);
else if(f->f_pTpl->optFormatForSQL == 2)
- doSQLEscape((char**)&v->iov_base, &v->iov_len,
- f->f_bMustBeFreed + iIOVused, 0);
+ doSQLEscape(&pVal, &iLenVal, f->f_bMustBeFreed + iIOVused, 0);
+ v->iov_base = pVal;
+ v->iov_len = iLenVal;
++v;
++iIOVused;
}
@@ -5974,7 +5983,7 @@ again:
logerror(f->f_un.f_fname);
}
} else if (f->f_flags & SYNC_FILE)
- (void) fsync(f->f_file);
+ fsync(f->f_file);
}
/* rgerhards 2004-11-09: fprintlog() is the actual driver for