Skip to content

Commit 419877c

Browse files
authored
Merge pull request #770 from redboltz/fix_wconversion
Added -Wconversion support for C++.
2 parents b759f5b + 17267ed commit 419877c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+498
-219
lines changed

erb/v1/cpp03_zone.hpp.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class zone {
5555
++m_tail;
5656
}
5757
void push_expand(void (*func)(void*), void* data) {
58-
const size_t nused = m_end - m_array;
58+
const size_t nused = static_cast<size_t>(m_end - m_array);
5959
size_t nnext;
6060
if(nused == 0) {
6161
nnext = (sizeof(finalizer) < 72/2) ?
@@ -201,12 +201,12 @@ inline char* zone::get_aligned(char* ptr, size_t align)
201201
inline void* zone::allocate_align(size_t size, size_t align)
202202
{
203203
char* aligned = get_aligned(m_chunk_list.m_ptr, align);
204-
size_t adjusted_size = size + (aligned - m_chunk_list.m_ptr);
204+
size_t adjusted_size = size + static_cast<size_t>(aligned - m_chunk_list.m_ptr);
205205
if (m_chunk_list.m_free < adjusted_size) {
206206
size_t enough_size = size + align - 1;
207207
char* ptr = allocate_expand(enough_size);
208208
aligned = get_aligned(ptr, align);
209-
adjusted_size = size + (aligned - m_chunk_list.m_ptr);
209+
adjusted_size = size + static_cast<size_t>(aligned - m_chunk_list.m_ptr);
210210
}
211211
m_chunk_list.m_free -= adjusted_size;
212212
m_chunk_list.m_ptr += adjusted_size;

include/msgpack/pack_template.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -838,51 +838,51 @@ msgpack_pack_inline_func(_ext)(msgpack_pack_user x, size_t l, int8_t type)
838838
case 1: {
839839
unsigned char buf[2];
840840
buf[0] = 0xd4;
841-
buf[1] = type;
841+
buf[1] = (unsigned char)type;
842842
msgpack_pack_append_buffer(x, buf, 2);
843843
} break;
844844
case 2: {
845845
unsigned char buf[2];
846846
buf[0] = 0xd5;
847-
buf[1] = type;
847+
buf[1] = (unsigned char)type;
848848
msgpack_pack_append_buffer(x, buf, 2);
849849
} break;
850850
case 4: {
851851
unsigned char buf[2];
852852
buf[0] = 0xd6;
853-
buf[1] = type;
853+
buf[1] = (unsigned char)type;
854854
msgpack_pack_append_buffer(x, buf, 2);
855855
} break;
856856
case 8: {
857857
unsigned char buf[2];
858858
buf[0] = 0xd7;
859-
buf[1] = type;
859+
buf[1] = (unsigned char)type;
860860
msgpack_pack_append_buffer(x, buf, 2);
861861
} break;
862862
case 16: {
863863
unsigned char buf[2];
864864
buf[0] = 0xd8;
865-
buf[1] = type;
865+
buf[1] = (unsigned char)type;
866866
msgpack_pack_append_buffer(x, buf, 2);
867867
} break;
868868
default:
869869
if(l < 256) {
870870
unsigned char buf[3];
871871
buf[0] = 0xc7;
872872
buf[1] = (unsigned char)l;
873-
buf[2] = type;
873+
buf[2] = (unsigned char)type;
874874
msgpack_pack_append_buffer(x, buf, 3);
875875
} else if(l < 65536) {
876876
unsigned char buf[4];
877877
buf[0] = 0xc8;
878878
_msgpack_store16(&buf[1], l);
879-
buf[3] = type;
879+
buf[3] = (unsigned char)type;
880880
msgpack_pack_append_buffer(x, buf, 4);
881881
} else {
882882
unsigned char buf[6];
883883
buf[0] = 0xc9;
884884
_msgpack_store32(&buf[1], l);
885-
buf[5] = type;
885+
buf[5] = (unsigned char)type;
886886
msgpack_pack_append_buffer(x, buf, 6);
887887
}
888888
break;
@@ -897,7 +897,7 @@ msgpack_pack_inline_func(_ext_body)(msgpack_pack_user x, const void* b, size_t l
897897
msgpack_pack_inline_func(_timestamp)(msgpack_pack_user x, const msgpack_timestamp* d)
898898
{
899899
if ((((int64_t)d->tv_sec) >> 34) == 0) {
900-
uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | d->tv_sec;
900+
uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | (uint64_t)d->tv_sec;
901901
if ((data64 & 0xffffffff00000000L) == 0) {
902902
// timestamp 32
903903
char buf[4];

include/msgpack/sysdep.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
#if MSGPACK_ENDIAN_LITTLE_BYTE
9696

9797
# if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
98-
# define _msgpack_be16(x) ntohs(x)
98+
# define _msgpack_be16(x) ntohs((uint16_t)x)
9999
# else
100100
# if defined(ntohs)
101101
# define _msgpack_be16(x) ntohs(x)
@@ -109,7 +109,7 @@
109109
# endif
110110

111111
# if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
112-
# define _msgpack_be32(x) ntohl(x)
112+
# define _msgpack_be32(x) ntohl((uint32_t)x)
113113
# else
114114
# if defined(ntohl)
115115
# define _msgpack_be32(x) ntohl(x)
@@ -154,16 +154,16 @@
154154

155155
#define _msgpack_load16(cast, from, to) do { \
156156
memcpy((cast*)(to), (from), sizeof(cast)); \
157-
*(to) = _msgpack_be16(*(to)); \
157+
*(to) = (cast)_msgpack_be16(*(to)); \
158158
} while (0);
159159

160160
#define _msgpack_load32(cast, from, to) do { \
161161
memcpy((cast*)(to), (from), sizeof(cast)); \
162-
*(to) = _msgpack_be32(*(to)); \
162+
*(to) = (cast)_msgpack_be32(*(to)); \
163163
} while (0);
164164
#define _msgpack_load64(cast, from, to) do { \
165165
memcpy((cast*)(to), (from), sizeof(cast)); \
166-
*(to) = _msgpack_be64(*(to)); \
166+
*(to) = (cast)_msgpack_be64(*(to)); \
167167
} while (0);
168168

169169
#define _msgpack_store16(to, num) \

include/msgpack/v1/adaptor/check_container_size.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ inline void check_container_size_for_ext<4>(std::size_t size) {
5353

5454
template <typename T>
5555
inline uint32_t checked_get_container_size(T size) {
56-
detail::check_container_size<sizeof(T)>(size);
56+
detail::check_container_size<sizeof(T)>(static_cast<std::size_t>(size));
5757
return static_cast<uint32_t>(size);
5858
}
5959

include/msgpack/v1/adaptor/cpp11/chrono.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct pack<std::chrono::system_clock::time_point> {
122122
* std::chrono::system_clock::duration::period::ratio::num
123123
/ std::chrono::system_clock::duration::period::ratio::den;
124124
if ((sec >> 34) == 0) {
125-
uint64_t data64 = (nanosec << 34) | sec;
125+
uint64_t data64 = (static_cast<uint64_t>(nanosec) << 34) | static_cast<uint64_t>(sec);
126126
if ((data64 & 0xffffffff00000000L) == 0) {
127127
// timestamp 32
128128
o.pack_ext(4, -1);
@@ -170,13 +170,13 @@ struct object_with_zone<std::chrono::system_clock::time_point> {
170170
* std::chrono::system_clock::duration::period::ratio::num
171171
/ std::chrono::system_clock::duration::period::ratio::den;
172172
if ((sec >> 34) == 0) {
173-
uint64_t data64 = (nanosec << 34) | sec;
173+
uint64_t data64 = (static_cast<uint64_t>(nanosec) << 34) | static_cast<uint64_t>(sec);
174174
if ((data64 & 0xffffffff00000000L) == 0) {
175175
// timestamp 32
176176
o.type = msgpack::type::EXT;
177177
o.via.ext.size = 4;
178178
char* p = static_cast<char*>(o.zone.allocate_no_align(o.via.ext.size + 1));
179-
p[0] = -1;
179+
p[0] = static_cast<char>(-1);
180180
uint32_t data32 = static_cast<uint32_t>(data64);
181181
_msgpack_store32(&p[1], data32);
182182
o.via.ext.ptr = p;
@@ -186,7 +186,7 @@ struct object_with_zone<std::chrono::system_clock::time_point> {
186186
o.type = msgpack::type::EXT;
187187
o.via.ext.size = 8;
188188
char* p = static_cast<char*>(o.zone.allocate_no_align(o.via.ext.size + 1));
189-
p[0] = -1;
189+
p[0] = static_cast<char>(-1);
190190
_msgpack_store64(&p[1], data64);
191191
o.via.ext.ptr = p;
192192
}
@@ -196,7 +196,7 @@ struct object_with_zone<std::chrono::system_clock::time_point> {
196196
o.type = msgpack::type::EXT;
197197
o.via.ext.size = 12;
198198
char* p = static_cast<char*>(o.zone.allocate_no_align(o.via.ext.size + 1));
199-
p[0] = -1;
199+
p[0] = static_cast<char>(-1);
200200
_msgpack_store32(&p[1], static_cast<uint32_t>(nanosec));
201201
_msgpack_store64(&p[1 + 4], sec);
202202
o.via.ext.ptr = p;

include/msgpack/v1/adaptor/ext.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ inline ext::ext(ext_ref const& x) {
178178
// size limit has already been checked at ext_ref's constructor
179179
m_data.reserve(x.size() + 1);
180180

181-
m_data.push_back(x.type());
181+
m_data.push_back(static_cast<char>(x.type()));
182182
m_data.insert(m_data.end(), x.data(), x.data() + x.size());
183183
}
184184

include/msgpack/v1/adaptor/fixint.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace type {
2222

2323
template <typename T>
2424
struct fix_int {
25+
typedef T value_type;
2526
fix_int() : value(0) { }
2627
fix_int(T value) : value(value) { }
2728

@@ -152,7 +153,7 @@ struct object<type::fix_int8> {
152153
}
153154
else {
154155
o.type = msgpack::type::POSITIVE_INTEGER;
155-
o.via.u64 = v.get();
156+
o.via.u64 = static_cast<uint64_t>(v.get());
156157
}
157158
}
158159
};
@@ -166,7 +167,7 @@ struct object<type::fix_int16> {
166167
}
167168
else {
168169
o.type = msgpack::type::POSITIVE_INTEGER;
169-
o.via.u64 = v.get();
170+
o.via.u64 = static_cast<uint64_t>(v.get());
170171
}
171172
}
172173
};
@@ -180,7 +181,7 @@ struct object<type::fix_int32> {
180181
}
181182
else {
182183
o.type = msgpack::type::POSITIVE_INTEGER;
183-
o.via.u64 = v.get();
184+
o.via.u64 = static_cast<uint64_t>(v.get());
184185
}
185186
}
186187
};
@@ -194,7 +195,7 @@ struct object<type::fix_int64> {
194195
}
195196
else {
196197
o.type = msgpack::type::POSITIVE_INTEGER;
197-
o.via.u64 = v.get();
198+
o.via.u64 = static_cast<uint64_t>(v.get());
198199
}
199200
}
200201
};

include/msgpack/v1/adaptor/int.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct object_sign<true> {
7373
}
7474
else {
7575
o.type = msgpack::type::POSITIVE_INTEGER;
76-
o.via.u64 = v;
76+
o.via.u64 = static_cast<uint64_t>(v);
7777
}
7878
}
7979
};
@@ -278,7 +278,7 @@ struct object<signed char> {
278278
}
279279
else {
280280
o.type = msgpack::type::POSITIVE_INTEGER;
281-
o.via.u64 = v;
281+
o.via.u64 = static_cast<uint64_t>(v);
282282
}
283283
}
284284
};
@@ -292,7 +292,7 @@ struct object<signed short> {
292292
}
293293
else {
294294
o.type = msgpack::type::POSITIVE_INTEGER;
295-
o.via.u64 = v;
295+
o.via.u64 = static_cast<uint64_t>(v);
296296
}
297297
}
298298
};
@@ -306,7 +306,7 @@ struct object<signed int> {
306306
}
307307
else {
308308
o.type = msgpack::type::POSITIVE_INTEGER;
309-
o.via.u64 = v;
309+
o.via.u64 = static_cast<uint64_t>(v);
310310
}
311311
}
312312
};
@@ -320,7 +320,7 @@ struct object<signed long> {
320320
}
321321
else {
322322
o.type = msgpack::type::POSITIVE_INTEGER;
323-
o.via.u64 = v;
323+
o.via.u64 = static_cast<uint64_t>(v);
324324
}
325325
}
326326
};
@@ -334,7 +334,7 @@ struct object<signed long long> {
334334
}
335335
else{
336336
o.type = msgpack::type::POSITIVE_INTEGER;
337-
o.via.u64 = v;
337+
o.via.u64 = static_cast<uint64_t>(v);
338338
}
339339
}
340340
};

include/msgpack/v1/detail/cpp03_zone.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class zone {
5555
++m_tail;
5656
}
5757
void push_expand(void (*func)(void*), void* data) {
58-
const size_t nused = m_end - m_array;
58+
const size_t nused = static_cast<size_t>(m_end - m_array);
5959
size_t nnext;
6060
if(nused == 0) {
6161
nnext = (sizeof(finalizer) < 72/2) ?
@@ -246,12 +246,12 @@ inline char* zone::get_aligned(char* ptr, size_t align)
246246
inline void* zone::allocate_align(size_t size, size_t align)
247247
{
248248
char* aligned = get_aligned(m_chunk_list.m_ptr, align);
249-
size_t adjusted_size = size + (aligned - m_chunk_list.m_ptr);
249+
size_t adjusted_size = size + static_cast<size_t>(aligned - m_chunk_list.m_ptr);
250250
if (m_chunk_list.m_free < adjusted_size) {
251251
size_t enough_size = size + align - 1;
252252
char* ptr = allocate_expand(enough_size);
253253
aligned = get_aligned(ptr, align);
254-
adjusted_size = size + (aligned - m_chunk_list.m_ptr);
254+
adjusted_size = size + static_cast<size_t>(aligned - m_chunk_list.m_ptr);
255255
}
256256
m_chunk_list.m_free -= adjusted_size;
257257
m_chunk_list.m_ptr += adjusted_size;

include/msgpack/v1/detail/cpp11_zone.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class zone {
6161
++m_tail;
6262
}
6363
void push_expand(void (*func)(void*), void* data) {
64-
const size_t nused = m_end - m_array;
64+
const size_t nused = static_cast<size_t>(m_end - m_array);
6565
size_t nnext;
6666
if(nused == 0) {
6767
nnext = (sizeof(finalizer) < 72/2) ?
@@ -239,12 +239,12 @@ inline char* zone::get_aligned(char* ptr, size_t align)
239239
inline void* zone::allocate_align(size_t size, size_t align)
240240
{
241241
char* aligned = get_aligned(m_chunk_list.m_ptr, align);
242-
size_t adjusted_size = size + (aligned - m_chunk_list.m_ptr);
242+
size_t adjusted_size = size + static_cast<size_t>(aligned - m_chunk_list.m_ptr);
243243
if (m_chunk_list.m_free < adjusted_size) {
244244
size_t enough_size = size + align - 1;
245245
char* ptr = allocate_expand(enough_size);
246246
aligned = get_aligned(ptr, align);
247-
adjusted_size = size + (aligned - m_chunk_list.m_ptr);
247+
adjusted_size = size + static_cast<size_t>(aligned - m_chunk_list.m_ptr);
248248
}
249249
m_chunk_list.m_free -= adjusted_size;
250250
m_chunk_list.m_ptr += adjusted_size;

0 commit comments

Comments
 (0)