summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2012-04-11 16:46:02 (GMT)
committerChristian Mollekopf <chrigi_1@fastmail.fm>2012-04-11 16:46:02 (GMT)
commitec1f10aeafe258099e131b2166c69100a5a81b39 (patch)
treefaa534667bdf8dedfdc2997c143bebf80cd11e6c
parent7fc92e626b844dd9cc3c6a498ee20a72be84819b (diff)
downloadlibkolabxml-ec1f10aeafe258099e131b2166c69100a5a81b39.tar.gz
Fixed implicit number conversions. -Wconversion breaks boost_foreach.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/base64.cpp26
-rw-r--r--src/shared_conversions.h6
-rw-r--r--src/uricode.h6
-rw-r--r--src/utils.cpp2
-rw-r--r--src/xcalconversions.h2
6 files changed, 22 insertions, 22 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 279b875..e4e28fc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,7 +9,7 @@ add_dependencies(kolabxml generate_bindings)
target_link_libraries(kolabxml ${XERCES_C} ${Boost_LIBRARIES} ${UUID})
# For the core library we can be stricter when compiling. This doesn't work with the auto generated code though.
-set_target_properties(kolabxml PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -Wl,--no-undefined")
+set_target_properties(kolabxml PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -Wconversion -Wl,--no-undefined")
set_target_properties(kolabxml PROPERTIES VERSION ${KOLABXML_VERSION} SOVERSION 0)
install(TARGETS kolabxml ${KOLAB_INSTALL_DIRECTORIES})
diff --git a/src/base64.cpp b/src/base64.cpp
index 2a863d1..dcb820c 100644
--- a/src/base64.cpp
+++ b/src/base64.cpp
@@ -49,8 +49,8 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
- char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
- char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+ char_array_4[1] = (unsigned char)(((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4));
+ char_array_4[2] = (unsigned char)(((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6));
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; (i <4) ; i++)
@@ -65,8 +65,8 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
- char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
- char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+ char_array_4[1] = (unsigned char)(((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4));
+ char_array_4[2] = (unsigned char)(((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6));
char_array_4[3] = char_array_3[2] & 0x3f;
for (j = 0; (j < i + 1); j++)
@@ -82,7 +82,7 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
}
std::string base64_decode(std::string const& encoded_string) {
- int in_len = encoded_string.size();
+ std::string::size_type in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
@@ -93,11 +93,11 @@ std::string base64_decode(std::string const& encoded_string) {
char_array_4[i++] = encoded_string[in_]; in_++;
if (i ==4) {
for (i = 0; i <4; i++)
- char_array_4[i] = base64_chars.find(char_array_4[i]);
+ char_array_4[i] = (unsigned char)(base64_chars.find(char_array_4[i]));
- char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
- char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
- char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
+ char_array_3[0] = (unsigned char)((char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4));
+ char_array_3[1] = (unsigned char)(((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2));
+ char_array_3[2] = (unsigned char)(((char_array_4[2] & 0x3) << 6) + char_array_4[3]);
for (i = 0; (i < 3); i++)
ret += char_array_3[i];
@@ -110,11 +110,11 @@ std::string base64_decode(std::string const& encoded_string) {
char_array_4[j] = 0;
for (j = 0; j <4; j++)
- char_array_4[j] = base64_chars.find(char_array_4[j]);
+ char_array_4[j] = (unsigned char)(base64_chars.find(char_array_4[j]));
- char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
- char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
- char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
+ char_array_3[0] = (unsigned char)((char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4));
+ char_array_3[1] = (unsigned char)(((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2));
+ char_array_3[2] = (unsigned char)(((char_array_4[2] & 0x3) << 6) + char_array_4[3]);
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
}
diff --git a/src/shared_conversions.h b/src/shared_conversions.h
index 8b42256..6165058 100644
--- a/src/shared_conversions.h
+++ b/src/shared_conversions.h
@@ -46,7 +46,7 @@ cDateTimePtr toDate(const date_time &dt)
{
cDateTimePtr date(new cDateTime());
date->setDate(dt.year(), dt.month(), dt.day());
- date->setTime(dt.hours(), dt.minutes(), dt.seconds());
+ date->setTime(dt.hours(), dt.minutes(), convertToInt(dt.seconds()));
if (dt.zone_present()) {
date->setUTC(true);
}
@@ -55,7 +55,7 @@ cDateTimePtr toDate(const date_time &dt)
date_time fromDateTime(const cDateTime &d)
{
- date_time date(d.year(), d.month(), d.day(), d.hour(), d.minute(), d.second());
+ date_time date(d.year(), fromInt<unsigned short>(d.month()), fromInt<unsigned short>(d.day()), fromInt<unsigned short>(d.hour()), fromInt<unsigned short>(d.minute()), fromInt<double>(d.second()));
if (d.isUTC()) {
//Setting both zone hours/and zone minutes to zero results in a Z being appended to indicate UTC
date.zone_hours(0);
@@ -66,7 +66,7 @@ date_time fromDateTime(const cDateTime &d)
date fromDate(const cDateTime &d)
{
- date de(d.year(), d.month(), d.day());
+ date de(fromInt<unsigned short>(d.year()), fromInt<unsigned short>(d.month()), fromInt<unsigned short>(d.day()));
return de;
}
diff --git a/src/uricode.h b/src/uricode.h
index 54bf542..5d1aa27 100644
--- a/src/uricode.h
+++ b/src/uricode.h
@@ -35,7 +35,7 @@ std::string UriDecode(const std::string & sSrc)
// for future extension"
const unsigned char * pSrc = (const unsigned char *)sSrc.c_str();
- const int SRC_LEN = sSrc.length();
+ const std::string::size_type SRC_LEN = sSrc.length();
const unsigned char * const SRC_END = pSrc + SRC_LEN;
const unsigned char * const SRC_LAST_DEC = SRC_END - 2; // last decodable '%'
@@ -50,7 +50,7 @@ std::string UriDecode(const std::string & sSrc)
if (-1 != (dec1 = HEX2DEC[*(pSrc + 1)])
&& -1 != (dec2 = HEX2DEC[*(pSrc + 2)]))
{
- *pEnd++ = (dec1 << 4) + dec2;
+ *pEnd++ = static_cast<char>((dec1 << 4) + dec2);
pSrc += 3;
continue;
}
@@ -97,7 +97,7 @@ std::string UriEncode(const std::string & sSrc)
{
const char DEC2HEX[16 + 1] = "0123456789ABCDEF";
const unsigned char * pSrc = (const unsigned char *)sSrc.c_str();
- const int SRC_LEN = sSrc.length();
+ const std::string::size_type SRC_LEN = sSrc.length();
unsigned char * const pStart = new unsigned char[SRC_LEN * 3];
unsigned char * pEnd = pStart;
const unsigned char * const SRC_END = pSrc + SRC_LEN;
diff --git a/src/utils.cpp b/src/utils.cpp
index c4fde94..9cf2007 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -196,7 +196,7 @@ std::string getErrorMessage()
std::string uriInlineEncoding(const std::string &s, const std::string &mimetype)
{
- return std::string("data:")+mimetype+std::string(";base64,")+base64_encode(reinterpret_cast<const unsigned char*>(s.c_str()), s.length());
+ return std::string("data:")+mimetype+std::string(";base64,")+base64_encode(reinterpret_cast<const unsigned char*>(s.c_str()), static_cast<unsigned int>(s.length()));
}
std::string uriInlineDecoding(const std::string &s, std::string &mimetype)
diff --git a/src/xcalconversions.h b/src/xcalconversions.h
index 3b16168..1390016 100644
--- a/src/xcalconversions.h
+++ b/src/xcalconversions.h
@@ -436,7 +436,7 @@ icalendar_2_0::AttachPropType fromAttachment(const Kolab::Attachment &a)
if (!a.uri().empty()) {
attachment.uri(a.uri());
} else if (!a.data().empty()) {
- attachment.binary(base64_encode(reinterpret_cast<const unsigned char*>(a.data().c_str()), a.data().length()));
+ attachment.binary(base64_encode(reinterpret_cast<const unsigned char*>(a.data().c_str()), static_cast<unsigned int>(a.data().length())));
p.baseParameter().push_back(icalendar_2_0::EncodingParamType(BASE64));
} else {
ERROR("no uri and no data");