Skip to content

Commit 7368961

Browse files
epistorBillyONeal
authored andcommitted
Address gcc warnings-as-errors in compression code, test improvements (#973)
Thanks for your contribution!
1 parent 204a526 commit 7368961

File tree

2 files changed

+53
-51
lines changed

2 files changed

+53
-51
lines changed

Release/src/http/common/http_compression.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ class zlib_compressor_base : public compress_provider
8989
throw std::runtime_error("Prior unrecoverable compression stream error " + std::to_string(m_state));
9090
}
9191

92+
#if defined(__clang__)
93+
#pragma clang diagnostic push
94+
#pragma clang diagnostic ignored "-Wtautological-constant-compare"
95+
#endif // __clang__
9296
if (input_size > std::numeric_limits<uInt>::max() || output_size > std::numeric_limits<uInt>::max())
97+
#if defined(__clang__)
98+
#pragma clang diagnostic pop
99+
#endif // __clang__
93100
{
94101
throw std::runtime_error("Compression input or output size out of range");
95102
}
@@ -183,7 +190,14 @@ class zlib_decompressor_base : public decompress_provider
183190
throw std::runtime_error("Prior unrecoverable decompression stream error " + std::to_string(m_state));
184191
}
185192

193+
#if defined(__clang__)
194+
#pragma clang diagnostic push
195+
#pragma clang diagnostic ignored "-Wtautological-constant-compare"
196+
#endif // __clang__
186197
if (input_size > std::numeric_limits<uInt>::max() || output_size > std::numeric_limits<uInt>::max())
198+
#if defined(__clang__)
199+
#pragma clang diagnostic pop
200+
#endif // __clang__
187201
{
188202
throw std::runtime_error("Compression input or output size out of range");
189203
}
@@ -297,13 +311,13 @@ class brotli_compressor : public compress_provider
297311
uint32_t block = 0,
298312
uint32_t nomodel = 0,
299313
uint32_t hint = 0)
300-
: m_algorithm(BROTLI)
301-
, m_window(window)
314+
: m_window(window)
302315
, m_quality(quality)
303316
, m_mode(mode)
304317
, m_block(block)
305318
, m_nomodel(nomodel)
306319
, m_hint(hint)
320+
, m_algorithm(BROTLI)
307321
{
308322
(void)reset();
309323
}
@@ -518,6 +532,7 @@ class brotli_decompressor : public decompress_provider
518532
// have to first allocate a guaranteed-large-enough buffer and then copy out of it, or we'd have to call
519533
// reset() if it failed due to insufficient output buffer space (and we'd need to use
520534
// BrotliDecoderGetErrorCode() to tell if that's why it failed)
535+
(void)hint;
521536
m_state = BrotliDecoderDecompressStream(m_stream, &avail_in, &next_in, &avail_out, &next_out, &total_out);
522537
if (m_state == BROTLI_DECODER_RESULT_ERROR)
523538
{

Release/tests/functional/http/client/compression_tests.cpp

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,12 @@ SUITE(compression_tests)
181181
bool compressible)
182182
{
183183
std::vector<uint8_t> input_buffer;
184-
std::vector<uint8_t> cmp_buffer;
185-
std::vector<uint8_t> dcmp_buffer;
186-
operation_result r;
187-
std::vector<size_t> chunk_sizes;
188-
size_t csize;
189-
size_t dsize;
190184
size_t i;
191-
size_t nn;
192185

193186
VERIFY_ARE_EQUAL(compressor->algorithm(), decompressor->algorithm());
194187

195188
input_buffer.reserve(buffer_size);
196-
for (size_t i = 0; i < buffer_size; ++i)
189+
for (i = 0; i < buffer_size; ++i)
197190
{
198191
uint8_t element;
199192
if (compressible)
@@ -209,59 +202,52 @@ SUITE(compression_tests)
209202
}
210203

211204
// compress in chunks
212-
csize = 0;
213-
cmp_buffer.resize(buffer_size); // pessimistic (or not, for non-compressible data)
214-
for (i = 0; i < buffer_size; i += chunk_size)
205+
std::vector<size_t> chunk_sizes;
206+
std::vector<uint8_t> cmp_buffer(buffer_size);
207+
size_t cmpsize = buffer_size;
208+
size_t csize = 0;
209+
operation_result r = {0};
210+
operation_hint hint = operation_hint::has_more;
211+
for (i = 0; i < buffer_size || csize == cmpsize || !r.done; i += r.input_bytes_processed)
215212
{
213+
if (i == buffer_size)
214+
{
215+
// the entire input buffer has been consumed by the compressor
216+
hint = operation_hint::is_last;
217+
}
218+
if (csize == cmpsize)
219+
{
220+
// extend the output buffer if there may be more compressed bytes to retrieve
221+
cmpsize += std::min(chunk_size, (size_t)200);
222+
cmp_buffer.resize(cmpsize);
223+
}
216224
r = compressor
217225
->compress(input_buffer.data() + i,
218226
std::min(chunk_size, buffer_size - i),
219227
cmp_buffer.data() + csize,
220-
std::min(chunk_size, buffer_size - csize),
221-
operation_hint::has_more)
228+
std::min(chunk_size, cmpsize - csize),
229+
hint)
222230
.get();
223-
VERIFY_ARE_EQUAL(r.input_bytes_processed, std::min(chunk_size, buffer_size - i));
224-
VERIFY_ARE_EQUAL(r.done, false);
231+
VERIFY_IS_TRUE(r.input_bytes_processed == std::min(chunk_size, buffer_size - i) ||
232+
r.output_bytes_produced == std::min(chunk_size, cmpsize - csize));
233+
VERIFY_IS_TRUE(hint == operation_hint::is_last || !r.done);
225234
chunk_sizes.push_back(r.output_bytes_produced);
226235
csize += r.output_bytes_produced;
227236
}
228-
if (i >= buffer_size)
229-
{
230-
size_t cmpsize = buffer_size;
231-
do
232-
{
233-
if (csize == cmpsize)
234-
{
235-
// extend the output buffer if there may be more compressed bytes to retrieve
236-
cmpsize += std::min(chunk_size, (size_t)200);
237-
cmp_buffer.resize(cmpsize);
238-
}
239-
r = compressor
240-
->compress(NULL,
241-
0,
242-
cmp_buffer.data() + csize,
243-
std::min(chunk_size, cmpsize - csize),
244-
operation_hint::is_last)
245-
.get();
246-
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
247-
chunk_sizes.push_back(r.output_bytes_produced);
248-
csize += r.output_bytes_produced;
249-
} while (csize == cmpsize);
250-
VERIFY_ARE_EQUAL(r.done, true);
251-
252-
// once more with no input, to assure no error and done
253-
r = compressor->compress(NULL, 0, NULL, 0, operation_hint::is_last).get();
254-
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
255-
VERIFY_ARE_EQUAL(r.output_bytes_produced, 0);
256-
VERIFY_ARE_EQUAL(r.done, true);
257-
}
237+
VERIFY_ARE_EQUAL(r.done, true);
238+
239+
// once more with no input or output, to assure no error and done
240+
r = compressor->compress(NULL, 0, NULL, 0, operation_hint::is_last).get();
241+
VERIFY_ARE_EQUAL(r.input_bytes_processed, 0);
242+
VERIFY_ARE_EQUAL(r.output_bytes_produced, 0);
243+
VERIFY_ARE_EQUAL(r.done, true);
258244

259245
cmp_buffer.resize(csize); // actual
260246

261247
// decompress in as-compressed chunks
262-
nn = 0;
263-
dsize = 0;
264-
dcmp_buffer.resize(buffer_size);
248+
std::vector<uint8_t> dcmp_buffer(buffer_size);
249+
size_t dsize = 0;
250+
size_t nn = 0;
265251
for (std::vector<size_t>::iterator it = chunk_sizes.begin(); it != chunk_sizes.end(); ++it)
266252
{
267253
if (*it)
@@ -358,7 +344,8 @@ SUITE(compression_tests)
358344

359345
void compress_test(std::shared_ptr<compress_factory> cfactory, std::shared_ptr<decompress_factory> dfactory)
360346
{
361-
size_t tuples[][2] = {{7999, 8192},
347+
size_t tuples[][2] = {{3, 1024},
348+
{7999, 8192},
362349
{8192, 8192},
363350
{16001, 8192},
364351
{16384, 8192},

0 commit comments

Comments
 (0)