| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 #ifndef NDEBUG | 81 #ifndef NDEBUG |
| 82 // The interface says that |iovecs| is not sacred, so scramble it to make sure | 82 // The interface says that |iovecs| is not sacred, so scramble it to make sure |
| 83 // that nobody depends on it. | 83 // that nobody depends on it. |
| 84 memset(&(*iovecs)[0], 0xa5, sizeof((*iovecs)[0]) * iovecs->size()); | 84 memset(&(*iovecs)[0], 0xa5, sizeof((*iovecs)[0]) * iovecs->size()); |
| 85 #endif | 85 #endif |
| 86 | 86 |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 off_t StringFileWriter::Seek(off_t offset, int whence) { | 90 FileOffset StringFileWriter::Seek(FileOffset offset, int whence) { |
| 91 DCHECK(offset_.IsValid()); | 91 DCHECK(offset_.IsValid()); |
| 92 | 92 |
| 93 size_t base_offset; | 93 size_t base_offset; |
| 94 | 94 |
| 95 switch (whence) { | 95 switch (whence) { |
| 96 case SEEK_SET: | 96 case SEEK_SET: |
| 97 base_offset = 0; | 97 base_offset = 0; |
| 98 break; | 98 break; |
| 99 | 99 |
| 100 case SEEK_CUR: | 100 case SEEK_CUR: |
| 101 base_offset = offset_.ValueOrDie(); | 101 base_offset = offset_.ValueOrDie(); |
| 102 break; | 102 break; |
| 103 | 103 |
| 104 case SEEK_END: | 104 case SEEK_END: |
| 105 base_offset = string_.size(); | 105 base_offset = string_.size(); |
| 106 break; | 106 break; |
| 107 | 107 |
| 108 default: | 108 default: |
| 109 LOG(ERROR) << "Seek(): invalid whence " << whence; | 109 LOG(ERROR) << "Seek(): invalid whence " << whence; |
| 110 return -1; | 110 return -1; |
| 111 } | 111 } |
| 112 | 112 |
| 113 off_t base_offset_offt; | 113 FileOffset base_offset_offt; |
| 114 if (!AssignIfInRange(&base_offset_offt, base_offset)) { | 114 if (!AssignIfInRange(&base_offset_offt, base_offset)) { |
| 115 LOG(ERROR) << "Seek(): base_offset " << base_offset << " invalid for off_t"; | 115 LOG(ERROR) << "Seek(): base_offset " << base_offset |
| 116 << " invalid for offset"; |
| 116 return -1; | 117 return -1; |
| 117 } | 118 } |
| 118 base::CheckedNumeric<off_t> new_offset(base_offset_offt); | 119 base::CheckedNumeric<FileOffset> new_offset(base_offset_offt); |
| 119 new_offset += offset; | 120 new_offset += offset; |
| 120 if (!new_offset.IsValid()) { | 121 if (!new_offset.IsValid()) { |
| 121 LOG(ERROR) << "Seek(): new_offset invalid"; | 122 LOG(ERROR) << "Seek(): new_offset invalid"; |
| 122 return -1; | 123 return -1; |
| 123 } | 124 } |
| 124 off_t new_offset_offt = new_offset.ValueOrDie(); | 125 FileOffset new_offset_offt = new_offset.ValueOrDie(); |
| 125 size_t new_offset_sizet; | 126 size_t new_offset_sizet; |
| 126 if (!AssignIfInRange(&new_offset_sizet, new_offset_offt)) { | 127 if (!AssignIfInRange(&new_offset_sizet, new_offset_offt)) { |
| 127 LOG(ERROR) << "Seek(): new_offset " << new_offset_offt | 128 LOG(ERROR) << "Seek(): new_offset " << new_offset_offt |
| 128 << " invalid for size_t"; | 129 << " invalid for size_t"; |
| 129 return -1; | 130 return -1; |
| 130 } | 131 } |
| 131 | 132 |
| 132 offset_ = new_offset_sizet; | 133 offset_ = new_offset_sizet; |
| 133 | 134 |
| 134 return offset_.ValueOrDie(); | 135 return offset_.ValueOrDie(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace crashpad | 138 } // namespace crashpad |
| OLD | NEW |