| OLD | NEW |
| 1 /* Copyright 2013 Google Inc. All Rights Reserved. | 1 /* Copyright 2013 Google Inc. 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 mem_input->buffer = buffer; | 44 mem_input->buffer = buffer; |
| 45 mem_input->length = length; | 45 mem_input->length = length; |
| 46 mem_input->pos = 0; | 46 mem_input->pos = 0; |
| 47 input.cb_ = &BrotliMemInputFunction; | 47 input.cb_ = &BrotliMemInputFunction; |
| 48 input.data_ = mem_input; | 48 input.data_ = mem_input; |
| 49 return input; | 49 return input; |
| 50 } | 50 } |
| 51 | 51 |
| 52 int BrotliMemOutputFunction(void* data, const uint8_t* buf, size_t count) { | 52 int BrotliMemOutputFunction(void* data, const uint8_t* buf, size_t count) { |
| 53 BrotliMemOutput* output = (BrotliMemOutput*)data; | 53 BrotliMemOutput* output = (BrotliMemOutput*)data; |
| 54 if (output->pos + count > output->length) { | 54 size_t limit = output->length - output->pos; |
| 55 return -1; | 55 if (count > limit) { |
| 56 count = limit; |
| 56 } | 57 } |
| 57 memcpy(output->buffer + output->pos, buf, count); | 58 memcpy(output->buffer + output->pos, buf, count); |
| 58 output->pos += count; | 59 output->pos += count; |
| 59 return (int)count; | 60 return (int)count; |
| 60 } | 61 } |
| 61 | 62 |
| 62 BrotliOutput BrotliInitMemOutput(uint8_t* buffer, size_t length, | 63 BrotliOutput BrotliInitMemOutput(uint8_t* buffer, size_t length, |
| 63 BrotliMemOutput* mem_output) { | 64 BrotliMemOutput* mem_output) { |
| 64 BrotliOutput output; | 65 BrotliOutput output; |
| 65 mem_output->buffer = buffer; | 66 mem_output->buffer = buffer; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 BrotliOutput out; | 122 BrotliOutput out; |
| 122 out.cb_ = BrotliFileOutputFunction; | 123 out.cb_ = BrotliFileOutputFunction; |
| 123 out.data_ = f; | 124 out.data_ = f; |
| 124 return out; | 125 return out; |
| 125 } | 126 } |
| 126 | 127 |
| 127 | 128 |
| 128 #if defined(__cplusplus) || defined(c_plusplus) | 129 #if defined(__cplusplus) || defined(c_plusplus) |
| 129 } /* extern "C" */ | 130 } /* extern "C" */ |
| 130 #endif | 131 #endif |
| OLD | NEW |