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

Side by Side Diff: src/core/SkPath.cpp

Issue 61913002: Adding error checks to SkRBuffer (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Added doc Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkFlattenableBuffers.cpp ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkBuffer.h" 10 #include "SkBuffer.h"
(...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 } 2075 }
2076 2076
2077 SkWBuffer buffer(storage); 2077 SkWBuffer buffer(storage);
2078 2078
2079 int32_t packed = ((fIsOval & 1) << kIsOval_SerializationShift) | 2079 int32_t packed = ((fIsOval & 1) << kIsOval_SerializationShift) |
2080 (fConvexity << kConvexity_SerializationShift) | 2080 (fConvexity << kConvexity_SerializationShift) |
2081 (fFillType << kFillType_SerializationShift) | 2081 (fFillType << kFillType_SerializationShift) |
2082 (fSegmentMask << kSegmentMask_SerializationShift) | 2082 (fSegmentMask << kSegmentMask_SerializationShift) |
2083 (fDirection << kDirection_SerializationShift) 2083 (fDirection << kDirection_SerializationShift)
2084 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O 2084 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O
2085 | (0x1 << kNewFormat_SerializationShift); 2085 | (0x1 << kNewFormat_SerializationShift)
2086 #endif 2086 #endif
2087 ;
2087 2088
2088 buffer.write32(packed); 2089 buffer.write32(packed);
2089 2090
2090 fPathRef->writeToBuffer(&buffer); 2091 fPathRef->writeToBuffer(&buffer);
2091 2092
2092 buffer.padToAlign4(); 2093 buffer.padToAlign4();
2093 return buffer.pos(); 2094 return buffer.pos();
2094 } 2095 }
2095 2096
2096 size_t SkPath::readFromMemory(const void* storage, size_t length) { 2097 size_t SkPath::readFromMemory(const void* storage, size_t length) {
2097 SkRBufferWithSizeCheck buffer(storage, length); 2098 SkRBufferWithSizeCheck buffer(storage, length);
2098 2099
2099 uint32_t packed = buffer.readS32(); 2100 int32_t packed;
2101 if (!buffer.readS32(&packed)) {
2102 return 0;
2103 }
2104
2100 fIsOval = (packed >> kIsOval_SerializationShift) & 1; 2105 fIsOval = (packed >> kIsOval_SerializationShift) & 1;
2101 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF; 2106 fConvexity = (packed >> kConvexity_SerializationShift) & 0xFF;
2102 fFillType = (packed >> kFillType_SerializationShift) & 0xFF; 2107 fFillType = (packed >> kFillType_SerializationShift) & 0xFF;
2103 fSegmentMask = (packed >> kSegmentMask_SerializationShift) & 0xF; 2108 fSegmentMask = (packed >> kSegmentMask_SerializationShift) & 0xF;
2104 fDirection = (packed >> kDirection_SerializationShift) & 0x3; 2109 fDirection = (packed >> kDirection_SerializationShift) & 0x3;
2105 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O 2110 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O
2106 bool newFormat = (packed >> kNewFormat_SerializationShift) & 1; 2111 bool newFormat = (packed >> kNewFormat_SerializationShift) & 1;
2107 #endif 2112 #endif
2108 2113
2109 fPathRef.reset(SkPathRef::CreateFromBuffer(&buffer 2114 SkPathRef* pathRef = SkPathRef::CreateFromBuffer(&buffer
2110 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O 2115 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O
2111 , newFormat, packed 2116 , newFormat, packed
2112 #endif 2117 #endif
2113 )); 2118 );
2114
2115 buffer.skipToAlign4();
2116 2119
2117 size_t sizeRead = 0; 2120 size_t sizeRead = 0;
2118 if (buffer.isValid()) { 2121 if (buffer.isValid()) {
2122 fPathRef.reset(pathRef);
2119 SkDEBUGCODE(this->validate();) 2123 SkDEBUGCODE(this->validate();)
2124 buffer.skipToAlign4();
2120 sizeRead = buffer.pos(); 2125 sizeRead = buffer.pos();
2126 } else if (NULL != pathRef) {
2127 // If the buffer is not valid, pathRef should be NULL
2128 sk_throw();
2121 } 2129 }
2122 return sizeRead; 2130 return sizeRead;
2123 } 2131 }
2124 2132
2125 /////////////////////////////////////////////////////////////////////////////// 2133 ///////////////////////////////////////////////////////////////////////////////
2126 2134
2127 #include "SkString.h" 2135 #include "SkString.h"
2128 2136
2129 static void append_scalar(SkString* str, SkScalar value) { 2137 static void append_scalar(SkString* str, SkScalar value) {
2130 SkString tmp; 2138 SkString tmp;
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
3006 switch (this->getFillType()) { 3014 switch (this->getFillType()) {
3007 case SkPath::kEvenOdd_FillType: 3015 case SkPath::kEvenOdd_FillType:
3008 case SkPath::kInverseEvenOdd_FillType: 3016 case SkPath::kInverseEvenOdd_FillType:
3009 w &= 1; 3017 w &= 1;
3010 break; 3018 break;
3011 default: 3019 default:
3012 break; 3020 break;
3013 } 3021 }
3014 return SkToBool(w); 3022 return SkToBool(w);
3015 } 3023 }
OLDNEW
« no previous file with comments | « src/core/SkFlattenableBuffers.cpp ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698