summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2009-08-05 11:42:55 +0200
committerPatrick Ohly <patrick.ohly@intel.com>2009-08-05 11:42:55 +0200
commita9e10a9900247fefd9e7399b0246d561fe07ffbb (patch)
treed97f558e6669cc88001a31c0f139f74109120da5
parentd0050cba6295866855a9641c988cccbc5e7a876b (diff)
TSettingsKeyImpl::SetValueByID: compiler warning about pointer aliasinglibsynthesis_3.0.2.28_at_pr_day+syncevolution-0.9
engineinterface.cpp: In member function 'sysync::TSyError sysync::TSettingsKeyImpl::SetValueByID(sysync::sInt32, sysync::sInt32, sysync::uInt16, const void*, sysync::memSize)': engineinterface.cpp:495: error: dereferencing pointer 'bP.140' does break strict-aliasing rules engineinterface.cpp:498: error: dereferencing pointer 'bP.141' does break strict-aliasing rules g++ 4.4 is unhappy about this code. Reading from the variable and writing into it via another pointer certainly looks a bit strange, although I guess it must work reliably (can't write before read). Better avoid the pointer casting and use a union...
-rw-r--r--src/sysync/engineinterface.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/sysync/engineinterface.cpp b/src/sysync/engineinterface.cpp
index e6a85fd..7fefed9 100644
--- a/src/sysync/engineinterface.cpp
+++ b/src/sysync/engineinterface.cpp
@@ -486,20 +486,26 @@ TSyError TSettingsKeyImpl::SetValueByID(
tempInt = *((sInt64 *)aBuffer);
intConv:
// convert integer into native type
- bP = &tempInt; // re-use as temp buffer
+ union {
+ sInt64 buffer64;
+ sInt32 buffer32;
+ sInt16 buffer16;
+ sInt8 buffer8;
+ } buffer;
+ bP = &buffer;
switch (valType) {
case VALTYPE_INT8:
- siz=1; *((sInt8 *)bP) = tempInt;
+ siz=1; buffer.buffer8 = tempInt;
break;
case VALTYPE_INT16:
- siz=2; *((sInt16 *)bP) = tempInt;
+ siz=2; buffer.buffer16 = tempInt;
break;
case VALTYPE_INT32:
- siz=4; *((sInt32 *)bP) = tempInt;
+ siz=4; buffer.buffer32 = tempInt;
break;
case VALTYPE_INT64:
case VALTYPE_TIME64: // native timestamp
- siz=8; *((sInt64 *)bP) = tempInt;
+ siz=8; buffer.buffer64 = tempInt;
break;
default:
// other types (like text) cannot set as integer