mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-24 09:12:30 +02:00
Fixed #226.
Suppressed warnings on MSVC++ 64bit environment. Added container size limit check.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -46,9 +47,10 @@ inline object const& operator>> (object const& o, std::unordered_map<K, V>& v)
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::unordered_map<K,V>& v)
|
||||
{
|
||||
o.pack_map(v.size());
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename std::unordered_map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
@@ -63,10 +65,11 @@ inline void operator<< (object::with_zone& o, const std::unordered_map<K,V>& v)
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
|
||||
object_kv* const pend = p + v.size();
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*size));
|
||||
object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
o.via.map.size = size;
|
||||
typename std::unordered_map<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
@@ -98,9 +101,10 @@ inline object const& operator>> (object const& o, std::unordered_multimap<K, V>&
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::unordered_multimap<K,V>& v)
|
||||
{
|
||||
o.pack_map(v.size());
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename std::unordered_multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
@@ -115,10 +119,11 @@ inline void operator<< (object::with_zone& o, const std::unordered_multimap<K,V>
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
|
||||
object_kv* const pend = p + v.size();
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*size));
|
||||
object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
o.via.map.size = size;
|
||||
typename std::unordered_multimap<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
|
||||
Reference in New Issue
Block a user