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

Side by Side Diff: third_party/WebKit/Source/core/xml/parser/SharedBufferReader.cpp

Issue 1571233003: Fix errors caused by unsafe conversions to/from size_t (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improved ALLOW_NUMERIC_ARG_TYPES_PROMOTABLE_TO Created 4 years, 11 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 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 SharedBufferReader::SharedBufferReader(PassRefPtr<SharedBuffer> buffer) 42 SharedBufferReader::SharedBufferReader(PassRefPtr<SharedBuffer> buffer)
43 : m_buffer(buffer) 43 : m_buffer(buffer)
44 , m_currentOffset(0) 44 , m_currentOffset(0)
45 { 45 {
46 } 46 }
47 47
48 SharedBufferReader::~SharedBufferReader() 48 SharedBufferReader::~SharedBufferReader()
49 { 49 {
50 } 50 }
51 51
52 int SharedBufferReader::readData(char* outputBuffer, unsigned askedToRead) 52 int SharedBufferReader::readData(char* outputBuffer, int askedToRead)
53 { 53 {
54 if (!m_buffer || m_currentOffset > m_buffer->size()) 54 if (!m_buffer || m_currentOffset > m_buffer->size())
55 return 0; 55 return 0;
56 56
57 unsigned bytesCopied = 0; 57 size_t bytesCopied = 0;
58 unsigned bytesLeft = m_buffer->size() - m_currentOffset; 58 size_t bytesLeft = m_buffer->size() - m_currentOffset;
59 unsigned lenToCopy = std::min(askedToRead, bytesLeft); 59 size_t lenToCopy = std::min(safeCast<size_t>(askedToRead), bytesLeft);
60 60
61 while (bytesCopied < lenToCopy) { 61 while (bytesCopied < lenToCopy) {
62 const char* data; 62 const char* data;
63 unsigned segmentSize = m_buffer->getSomeData(data, m_currentOffset); 63 size_t segmentSize = m_buffer->getSomeData(data, m_currentOffset);
64 if (!segmentSize) 64 if (!segmentSize)
65 break; 65 break;
66 66
67 segmentSize = std::min(segmentSize, lenToCopy - bytesCopied); 67 segmentSize = std::min(segmentSize, lenToCopy - bytesCopied);
68 memcpy(outputBuffer + bytesCopied, data, segmentSize); 68 memcpy(outputBuffer + bytesCopied, data, segmentSize);
69 bytesCopied += segmentSize; 69 bytesCopied += segmentSize;
70 m_currentOffset += segmentSize; 70 m_currentOffset += segmentSize;
71 } 71 }
72 72
73 return bytesCopied; 73 return safeCast<int>(bytesCopied);
74 } 74 }
75 75
76 } // namespace blink 76 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698