Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: content/common/page_state_serialization.cc

Issue 649533003: C++11 declares a type safe null pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Presubmit errors Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/page_state_serialization.h" 5 #include "content/common/page_state_serialization.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 void WriteData(const void* data, int length, SerializeObject* obj) { 208 void WriteData(const void* data, int length, SerializeObject* obj) {
209 obj->pickle.WriteData(static_cast<const char*>(data), length); 209 obj->pickle.WriteData(static_cast<const char*>(data), length);
210 } 210 }
211 211
212 void ReadData(SerializeObject* obj, const void** data, int* length) { 212 void ReadData(SerializeObject* obj, const void** data, int* length) {
213 const char* tmp; 213 const char* tmp;
214 if (obj->pickle.ReadData(&obj->iter, &tmp, length)) { 214 if (obj->pickle.ReadData(&obj->iter, &tmp, length)) {
215 *data = tmp; 215 *data = tmp;
216 } else { 216 } else {
217 obj->parse_error = true; 217 obj->parse_error = true;
218 *data = NULL; 218 *data = nullptr;
219 *length = 0; 219 *length = 0;
220 } 220 }
221 } 221 }
222 222
223 void WriteInteger(int data, SerializeObject* obj) { 223 void WriteInteger(int data, SerializeObject* obj) {
224 obj->pickle.WriteInt(data); 224 obj->pickle.WriteInt(data);
225 } 225 }
226 226
227 int ReadInteger(SerializeObject* obj) { 227 int ReadInteger(SerializeObject* obj) {
228 int tmp; 228 int tmp;
(...skipping 13 matching lines...) Expand all
242 return tmp; 242 return tmp;
243 obj->parse_error = true; 243 obj->parse_error = true;
244 return 0; 244 return 0;
245 } 245 }
246 246
247 void WriteReal(double data, SerializeObject* obj) { 247 void WriteReal(double data, SerializeObject* obj) {
248 WriteData(&data, sizeof(double), obj); 248 WriteData(&data, sizeof(double), obj);
249 } 249 }
250 250
251 double ReadReal(SerializeObject* obj) { 251 double ReadReal(SerializeObject* obj) {
252 const void* tmp = NULL; 252 const void* tmp = nullptr;
253 int length = 0; 253 int length = 0;
254 double value = 0.0; 254 double value = 0.0;
255 ReadData(obj, &tmp, &length); 255 ReadData(obj, &tmp, &length);
256 if (length == static_cast<int>(sizeof(double))) { 256 if (length == static_cast<int>(sizeof(double))) {
257 // Use memcpy, as tmp may not be correctly aligned. 257 // Use memcpy, as tmp may not be correctly aligned.
258 memcpy(&value, tmp, sizeof(double)); 258 memcpy(&value, tmp, sizeof(double));
259 } else { 259 } else {
260 obj->parse_error = true; 260 obj->parse_error = true;
261 } 261 }
262 return value; 262 return value;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 size_t length_in_bytes = str.string().length() * sizeof(base::char16); 309 size_t length_in_bytes = str.string().length() * sizeof(base::char16);
310 310
311 CHECK_LT(length_in_bytes, 311 CHECK_LT(length_in_bytes,
312 static_cast<size_t>(std::numeric_limits<int>::max())); 312 static_cast<size_t>(std::numeric_limits<int>::max()));
313 obj->pickle.WriteInt(length_in_bytes); 313 obj->pickle.WriteInt(length_in_bytes);
314 obj->pickle.WriteBytes(data, length_in_bytes); 314 obj->pickle.WriteBytes(data, length_in_bytes);
315 } 315 }
316 } 316 }
317 317
318 // This reads a serialized NullableString16 from obj. If a string can't be 318 // This reads a serialized NullableString16 from obj. If a string can't be
319 // read, NULL is returned. 319 // read, nullptr is returned.
320 const base::char16* ReadStringNoCopy(SerializeObject* obj, int* num_chars) { 320 const base::char16* ReadStringNoCopy(SerializeObject* obj, int* num_chars) {
321 int length_in_bytes; 321 int length_in_bytes;
322 if (!obj->pickle.ReadInt(&obj->iter, &length_in_bytes)) { 322 if (!obj->pickle.ReadInt(&obj->iter, &length_in_bytes)) {
323 obj->parse_error = true; 323 obj->parse_error = true;
324 return NULL; 324 return nullptr;
325 } 325 }
326 326
327 if (length_in_bytes < 0) 327 if (length_in_bytes < 0)
328 return NULL; 328 return nullptr;
329 329
330 const char* data; 330 const char* data;
331 if (!obj->pickle.ReadBytes(&obj->iter, &data, length_in_bytes)) { 331 if (!obj->pickle.ReadBytes(&obj->iter, &data, length_in_bytes)) {
332 obj->parse_error = true; 332 obj->parse_error = true;
333 return NULL; 333 return nullptr;
334 } 334 }
335 335
336 if (num_chars) 336 if (num_chars)
337 *num_chars = length_in_bytes / sizeof(base::char16); 337 *num_chars = length_in_bytes / sizeof(base::char16);
338 return reinterpret_cast<const base::char16*>(data); 338 return reinterpret_cast<const base::char16*>(data);
339 } 339 }
340 340
341 base::NullableString16 ReadString(SerializeObject* obj) { 341 base::NullableString16 ReadString(SerializeObject* obj) {
342 int num_chars; 342 int num_chars;
343 const base::char16* chars = ReadStringNoCopy(obj, &num_chars); 343 const base::char16* chars = ReadStringNoCopy(obj, &num_chars);
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 float device_scale_factor, 741 float device_scale_factor,
742 ExplodedPageState* exploded) { 742 ExplodedPageState* exploded) {
743 g_device_scale_factor_for_testing = device_scale_factor; 743 g_device_scale_factor_for_testing = device_scale_factor;
744 bool rv = DecodePageState(encoded, exploded); 744 bool rv = DecodePageState(encoded, exploded);
745 g_device_scale_factor_for_testing = 0.0; 745 g_device_scale_factor_for_testing = 0.0;
746 return rv; 746 return rv;
747 } 747 }
748 #endif 748 #endif
749 749
750 } // namespace content 750 } // namespace content
OLDNEW
« no previous file with comments | « content/common/media/media_stream_options.h ('k') | content/common/page_state_serialization_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698