Skip to content

Commit 8aeccf0

Browse files
committed
Resolve some clang warnings.
Update _httpUpdate and http_read code to properly handle timeouts.
1 parent f89856b commit 8aeccf0

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

cups/http.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,23 +2477,32 @@ _httpUpdate(http_t *http, // I - HTTP connection
24772477
{
24782478
ssize_t bytes; // Bytes "peeked" from connection
24792479

2480-
// Peek at the incoming data...
2481-
if ((bytes = httpPeek(http, line, sizeof(line) - 1)) < 0)
2480+
// See whether our read buffer is full...
2481+
DEBUG_printf("2_httpUpdate: used=%d", http->used);
2482+
2483+
if (http->used > 0 && !memchr(http->buffer, '\n', (size_t)http->used) && (size_t)http->used < sizeof(http->buffer))
24822484
{
2483-
// Unable to peek, return an error...
2484-
*status = HTTP_STATUS_ERROR;
2485-
return (0);
2485+
// No, try filling in more data...
2486+
if ((bytes = http_read(http, http->buffer + http->used, sizeof(http->buffer) - (size_t)http->used)) > 0)
2487+
{
2488+
DEBUG_printf("2_httpUpdate: Read %d bytes.", (int)bytes);
2489+
http->used += (int)bytes;
2490+
}
24862491
}
24872492

2488-
// Nul-terminate the data and see if we have a newline...
2489-
line[bytes] = '\0';
2490-
2491-
if (!strchr(line, '\n'))
2493+
// Peek at the incoming data...
2494+
if (!http->used || !memchr(http->buffer, '\n', (size_t)http->used))
24922495
{
24932496
// Don't have a full line, tell the reader to try again when there is more data...
2494-
*status = HTTP_STATUS_CONTINUE;
2497+
DEBUG_puts("1_htttpUpdate: No newline in buffer yet.");
2498+
if ((size_t)http->used == sizeof(http->buffer))
2499+
*status = HTTP_STATUS_ERROR;
2500+
else
2501+
*status = HTTP_STATUS_CONTINUE;
24952502
return (0);
24962503
}
2504+
2505+
DEBUG_puts("2_httpUpdate: Found newline in buffer.");
24972506
}
24982507

24992508
// Grab a single line from the connection...
@@ -3672,7 +3681,7 @@ http_read(http_t *http, // I - HTTP connection
36723681

36733682
if (!http->blocking || http->timeout_value > 0.0)
36743683
{
3675-
while (!httpWait(http, http->wait_value))
3684+
while (!_httpWait(http, http->wait_value, true))
36763685
{
36773686
if (http->timeout_cb && (*http->timeout_cb)(http, http->timeout_data))
36783687
continue;

cups/oauth.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,10 @@ cupsOAuthGetUserId(
12731273
}
12741274

12751275
// Get the response...
1276-
while ((status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);
1276+
do
1277+
{
1278+
status = httpUpdate(http);
1279+
} while (status == HTTP_STATUS_CONTINUE);
12771280

12781281
user_id_value = oauth_copy_response(http);
12791282
user_id_claims = cupsJSONImportString(user_id_value);

pdfio

tools/ipptransform.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4207,7 +4207,11 @@ xform_document(
42074207
fprintf(stderr, "DEBUG: cupsPageSize=[%g %g]\n", ras.header.cupsPageSize[0], ras.header.cupsPageSize[1]);
42084208

42094209
if (!(ras.start_job)(&ras, cb, ctx))
4210+
{
4211+
CGPDFDocumentRelease(document);
4212+
CGContextRelease(context);
42104213
return (false);
4214+
}
42114215

42124216
// Render pages in the PDF...
42134217
if (options->multiple_document_handling == IPPOPT_HANDLING_UNCOLLATED_COPIES)

0 commit comments

Comments
 (0)