Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21693038 authored by Yunlian Jiang's avatar Yunlian Jiang Committed by George Burgess IV
Browse files

fix Access to field 'targets' results in a dereference of a null pointer

This fixes Access to field 'targets' results in a dereference of a null
pointer

Test: the warning is gone.
Change-Id: If5d8c1c87c4cf77252bd5d262eefeba30c772fe7
parent 11f51b04
Loading
Loading
Loading
Loading
+12 −2
Original line number Original line Diff line number Diff line
@@ -51,8 +51,13 @@ camera_status_t ACaptureRequest_addTarget(
        ACaptureRequest* req, const ACameraOutputTarget* target) {
        ACaptureRequest* req, const ACameraOutputTarget* target) {
    ATRACE_CALL();
    ATRACE_CALL();
    if (req == nullptr || req->targets == nullptr || target == nullptr) {
    if (req == nullptr || req->targets == nullptr || target == nullptr) {
        void* req_targets;
        if (req != nullptr)
            req_targets = req->targets;
        else
            req_targets = nullptr;
        ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p",
        ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p",
                __FUNCTION__, req, req->targets, target);
                __FUNCTION__, req, req_targets, target);
        return ACAMERA_ERROR_INVALID_PARAMETER;
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    }
    auto pair = req->targets->mOutputs.insert(*target);
    auto pair = req->targets->mOutputs.insert(*target);
@@ -67,8 +72,13 @@ camera_status_t ACaptureRequest_removeTarget(
        ACaptureRequest* req, const ACameraOutputTarget* target) {
        ACaptureRequest* req, const ACameraOutputTarget* target) {
    ATRACE_CALL();
    ATRACE_CALL();
    if (req == nullptr || req->targets == nullptr || target == nullptr) {
    if (req == nullptr || req->targets == nullptr || target == nullptr) {
        void* req_targets;
        if (req != nullptr)
            req_targets = req->targets;
        else
            req_targets = nullptr;
        ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p",
        ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p",
                __FUNCTION__, req, req->targets, target);
                __FUNCTION__, req, req_targets, target);
        return ACAMERA_ERROR_INVALID_PARAMETER;
        return ACAMERA_ERROR_INVALID_PARAMETER;
    }
    }
    req->targets->mOutputs.erase(*target);
    req->targets->mOutputs.erase(*target);