diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2007-06-26 07:05:23 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2007-06-26 07:05:23 +0000 |
commit | 10df374d97072a1403c2abc966d6c10d72f3b47a (patch) | |
tree | 7d84a57392541f5b32ab2a5db6dbe6bb707850b9 /syslogd.c | |
parent | 561fdaf26ffe064c951b9f34ec1bbec2aba165f5 (diff) | |
download | rsyslog-10df374d97072a1403c2abc966d6c10d72f3b47a.tar.gz rsyslog-10df374d97072a1403c2abc966d6c10d72f3b47a.tar.xz rsyslog-10df374d97072a1403c2abc966d6c10d72f3b47a.zip |
fixed code in iovCreate() that broke C's strict aliasing rules
Diffstat (limited to 'syslogd.c')
-rw-r--r-- | syslogd.c | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -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 |