Hello noel,
I'd like you to do a code review. Please execute
g4 diff -c 10581312
or point your web browser to
http://mondrian/10581312
to review the following code:
Change 10581312 by nigel...@nigeltao-srcgears2 on 2009/03/24 19:09:52 *pending*
Fix our use of libjpeg -- our fill_input_buffer function was
not taking into account the number of bytes already in the
buffer.
PRESUBMIT=passed
R=noel
[email protected]
DELTA=12 (6 added, 0 deleted, 6 changed)
OCL=10581312
Affected files ...
...
//depot/googleclient/gears/opensource/gears/desktop/meta_data_extraction.cc#3
edit
12 delta lines: 6 added, 0 deleted, 6 changed
Also consider running:
g4 lint -c 10581312
which verifies that the changelist doesn't introduce new style violations.
If you can't do the review, please let me know as soon as possible. During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately. Visit
http://www/eng/code_review.html for more information.
This is a semiautomated message from "g4 mail". Complaints or suggestions?
Mail [email protected].
Change 10581312 by nigel...@nigeltao-srcgears2 on 2009/03/24 19:09:52 *pending*
Fix our use of libjpeg -- our fill_input_buffer function was
not taking into account the number of bytes already in the
buffer.
Affected files ...
...
//depot/googleclient/gears/opensource/gears/desktop/meta_data_extraction.cc#3
edit
====
//depot/googleclient/gears/opensource/gears/desktop/meta_data_extraction.cc#3 -
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/desktop/meta_data_extraction.cc
====
# action=edit type=text
--- googleclient/gears/opensource/gears/desktop/meta_data_extraction.cc
2009-04-01 10:57:34.000000000 +1100
+++ googleclient/gears/opensource/gears/desktop/meta_data_extraction.cc
2009-04-01 10:51:50.000000000 +1100
@@ -63,10 +63,11 @@
}
+static const size_t kJpegBlobReadContextBufferSize = 1024;
struct JpegBlobReadContext {
BlobInterface *blob;
int64 offset;
- uint8 buffer[1024];
+ uint8 buffer[kJpegBlobReadContextBufferSize];
};
@@ -81,12 +82,13 @@
static boolean JpegBlobFillInputBuffer(j_decompress_ptr jd) {
JpegBlobReadContext *context =
reinterpret_cast<JpegBlobReadContext*>(jd->client_data);
- int bytes_read = static_cast<int>(
- context->blob->Read(context->buffer, context->offset, 1024));
+ int bytes_read = static_cast<int>(context->blob->Read(
+ context->buffer, context->offset, kJpegBlobReadContextBufferSize));
if (bytes_read <= 0) {
return FALSE;
}
- assert(bytes_read >= 0 && bytes_read <= 1024);
+ assert(bytes_read >= 0 &&
+ bytes_read <= static_cast<int>(kJpegBlobReadContextBufferSize));
context->offset += bytes_read;
jd->src->next_input_byte = context->buffer;
jd->src->bytes_in_buffer = bytes_read;
@@ -100,11 +102,15 @@
}
JpegBlobReadContext *context =
reinterpret_cast<JpegBlobReadContext*>(jd->client_data);
- if (static_cast<unsigned int>(num_bytes) < jd->src->bytes_in_buffer) {
+ assert(jd->src->bytes_in_buffer >= 0 &&
+ jd->src->bytes_in_buffer <= kJpegBlobReadContextBufferSize);
+ int extra_bytes_needed =
+ num_bytes - static_cast<int>(jd->src->bytes_in_buffer);
+ if (extra_bytes_needed < 0) {
jd->src->next_input_byte += num_bytes;
jd->src->bytes_in_buffer -= num_bytes;
} else {
- context->offset += num_bytes;
+ context->offset += extra_bytes_needed;
jd->src->next_input_byte = context->buffer;
jd->src->bytes_in_buffer = 0;
}