From 3a2e1ce8eaa22b57af0baca0049cd7f8d2627774 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Wed, 20 Jan 2021 21:06:20 -0800 Subject: nativewindow: report errors on error to allocate a handle At the moment, `outBuffer` won't be set if `err == 0 && gbuffer->handle != nullptr`, even though we return a zero value for `err`. This causes us to pass nullptr to AHardwareBuffer_release in AHardwareBuffer_isSupported, which isn't correct. Caught by the static analyzer: > frameworks/native/libs/nativewindow/AHardwareBuffer.cpp:394:9: warning: Null passed to a callee that requires a non-null 1st parameter [clang-analyzer-nullability.NullPassedToNonnull] This also replaces 0 with nullptr, since we're checking a pointer's value here. Bug: None Test: TreeHugger Change-Id: Id2fad234f98eda71b06419193e15cbfb5fa39bf1 --- libs/nativewindow/AHardwareBuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libs/nativewindow/AHardwareBuffer.cpp') diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp index 1ec73ce961..3030068c65 100644 --- a/libs/nativewindow/AHardwareBuffer.cpp +++ b/libs/nativewindow/AHardwareBuffer.cpp @@ -51,13 +51,13 @@ int AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc, AHardwareBuffer** std::string("AHardwareBuffer pid [") + std::to_string(getpid()) + "]")); status_t err = gbuffer->initCheck(); - if (err != 0 || gbuffer->handle == 0) { + if (err != 0 || gbuffer->handle == nullptr) { if (err == NO_MEMORY) { GraphicBuffer::dumpAllocationsToSystemLog(); } ALOGE("GraphicBuffer(w=%u, h=%u, lc=%u) failed (%s), handle=%p", desc->width, desc->height, desc->layers, strerror(-err), gbuffer->handle); - return err; + return err == 0 ? UNKNOWN_ERROR : err; } *outBuffer = AHardwareBuffer_from_GraphicBuffer(gbuffer.get()); -- cgit v1.2.3-59-g8ed1b