Skip to content

Commit

Permalink
More Coverity fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Jan 25, 2024
1 parent 368c385 commit b88bc4b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
4 changes: 4 additions & 0 deletions pappl/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,8 @@ _papplJobSubmitFile(
headersize = read(fd, (char *)header, sizeof(header));
close(fd);

_papplRWLockRead(job->system);

if (!memcmp(header, "%PDF", 4))
job->format = "application/pdf";
else if (!memcmp(header, "%!", 2))
Expand All @@ -821,6 +823,8 @@ _papplJobSubmitFile(
job->format = "image/urf";
else if (job->system->mime_cb)
job->format = (job->system->mime_cb)(header, (size_t)headersize, job->system->mime_cbdata);

_papplRWUnlock(job->system);
}
}

Expand Down
10 changes: 5 additions & 5 deletions pappl/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ papplLog(pappl_system_t *system, // I - System
return;
}

if (level < system->loglevel)
if (level < papplSystemGetLogLevel(system))
return;

va_start(ap, message);
Expand Down Expand Up @@ -128,7 +128,7 @@ _papplLogAttributes(
if (!client || !title || !ipp)
return;

if (client->system->loglevel > PAPPL_LOGLEVEL_DEBUG)
if (papplSystemGetLogLevel(client->system) > PAPPL_LOGLEVEL_DEBUG)
return;

major = ippGetVersion(ipp, &minor);
Expand Down Expand Up @@ -188,7 +188,7 @@ papplLogClient(
if (!client || !message)
return;

if (level < client->system->loglevel)
if (level < papplSystemGetLogLevel(client->system))
return;

snprintf(cmessage, sizeof(cmessage), "[Client %d] %s", client->number, message);
Expand Down Expand Up @@ -255,7 +255,7 @@ papplLogJob(
if (!job || !message)
return;

if (level < job->system->loglevel)
if (level < papplSystemGetLogLevel(job->system))
return;

snprintf(jmessage, sizeof(jmessage), "[Job %d] %s", job->job_id, message);
Expand Down Expand Up @@ -347,7 +347,7 @@ papplLogPrinter(
if (!printer || !message)
return;

if (level < printer->system->loglevel)
if (level < papplSystemGetLogLevel(printer->system))
return;

// Prefix the message with "[Printer foo]", making sure to not insert any
Expand Down
4 changes: 2 additions & 2 deletions pappl/printer-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,12 @@ papplPrinterOpenDevice(
pappl_device_t *device = NULL; // Open device


if (!printer || printer->device_in_use || printer->processing_job || !printer->device_uri)
if (!printer)
return (NULL);

_papplRWLockWrite(printer);

if (!printer->device_in_use && !printer->processing_job)
if (!printer->device_in_use && !printer->processing_job && printer->device_uri)
{
// papplLogPrinter(printer, PAPPL_LOGLEVEL_DEBUG, "Opening device for status/maintenance.");

Expand Down
18 changes: 11 additions & 7 deletions pappl/printer-ipp.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
//
// Printer IPP processing for the Printer Application Framework
//
// Copyright © 2019-2023 by Michael R Sweet.
// Copyright © 2019-2024 by Michael R Sweet.
// Copyright © 2010-2019 by Apple Inc.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
//

//
// Include necessary headers...
//

#include "pappl-private.h"


Expand Down Expand Up @@ -1630,10 +1626,20 @@ ipp_get_printer_attributes(
// Printer


_papplRWLockRead(printer->system);
_papplRWLockRead(printer);

if (!printer->device_in_use && !printer->processing_job && (time(NULL) - printer->status_time) > 1 && printer->driver_data.status_cb)
{
// Update printer status...
_papplRWUnlock(printer);
_papplRWUnlock(printer->system);

(printer->driver_data.status_cb)(printer);

_papplRWLockRead(printer->system);
_papplRWLockWrite(printer);

printer->status_time = time(NULL);
}

Expand All @@ -1642,8 +1648,6 @@ ipp_get_printer_attributes(

papplClientRespondIPP(client, IPP_STATUS_OK, NULL);

_papplRWLockRead(printer->system);
_papplRWLockRead(printer);
_papplPrinterCopyAttributesNoLock(printer, client, ra, ippGetString(ippFindAttribute(client->request, "document-format", IPP_TAG_MIMETYPE), 0, NULL));
_papplRWUnlock(printer);
_papplRWUnlock(printer->system);
Expand Down
2 changes: 1 addition & 1 deletion pappl/printer-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ papplPrinterSetUSB(
_papplRWUnlock(printer);

// Start USB gadget if needed...
if (printer->system->is_running && printer->system->default_printer_id == printer->printer_id && (printer->system->options & PAPPL_SOPTIONS_USB_PRINTER))
if (papplSystemIsRunning(printer->system) && papplSystemGetDefaultPrinterID(printer->system) == printer->printer_id && (printer->system->options & PAPPL_SOPTIONS_USB_PRINTER))
{
pthread_t tid; // Thread ID

Expand Down
2 changes: 2 additions & 0 deletions xcode/pappl.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_GCD_PERFORMANCE = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down Expand Up @@ -1277,6 +1278,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_GCD_PERFORMANCE = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
Expand Down

0 comments on commit b88bc4b

Please sign in to comment.