OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 152 } |
153 | 153 |
154 if (num_elements > MAX_LARGE_INDEX) { | 154 if (num_elements > MAX_LARGE_INDEX) { |
155 O3D_ERROR(service_locator()) | 155 O3D_ERROR(service_locator()) |
156 << "The maximum number of elements in a buffer is " << MAX_LARGE_INDEX | 156 << "The maximum number of elements in a buffer is " << MAX_LARGE_INDEX |
157 << "."; | 157 << "."; |
158 return false; | 158 return false; |
159 } | 159 } |
160 | 160 |
161 size_t size_in_bytes = num_elements * stride_; | 161 size_t size_in_bytes = num_elements * stride_; |
| 162 // Check for size_t overflow. |
| 163 if (size_in_bytes / stride_ != num_elements) { |
| 164 O3D_ERROR(service_locator()) |
| 165 << "Attempt to allocate too many elements for the current set of " |
| 166 << "fields on buffer."; |
| 167 return false; |
| 168 } |
162 | 169 |
163 if (size_in_bytes == 0) { | 170 if (size_in_bytes == 0) { |
164 O3D_ERROR(service_locator()) | 171 O3D_ERROR(service_locator()) |
165 << "Attempt to allocate zero bytes for Buffer '" << name() << "'"; | 172 << "Attempt to allocate zero bytes for Buffer '" << name() << "'"; |
166 return false; | 173 return false; |
167 } | 174 } |
168 | 175 |
169 bool success = true; | 176 bool success = true; |
170 if (!ConcreteAllocate(size_in_bytes)) { | 177 if (!ConcreteAllocate(size_in_bytes)) { |
171 num_elements = 0; | 178 num_elements = 0; |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 locked_ = buffer_->Lock(access_mode, &data_); | 604 locked_ = buffer_->Lock(access_mode, &data_); |
598 if (!locked_) { | 605 if (!locked_) { |
599 O3D_ERROR(buffer_->service_locator()) | 606 O3D_ERROR(buffer_->service_locator()) |
600 << "Unable to lock buffer '" << buffer_->name() << "'"; | 607 << "Unable to lock buffer '" << buffer_->name() << "'"; |
601 } | 608 } |
602 } | 609 } |
603 return data_; | 610 return data_; |
604 } | 611 } |
605 | 612 |
606 } // namespace o3d | 613 } // namespace o3d |
OLD | NEW |