Fix NDK CameraManager crash when no cameras exist
The NDK CameraManager only lists cameras that support camera API v2. For
a device that only supports v1 the list comes back empty. This results
in allocating an array of size zero. This array was then intialized with
a nullptr. This is fine if the array contains at least one item but in
the case where there are no cameras this will cause a buffer overflow.
This change removes the initialization which fixes the crash.
Test: manual - ran camera CTS tests
Change-Id: Ie1c872ff66997d55572fd855f20b56bd58b01752
diff --git a/camera/ndk/impl/ACameraManager.cpp b/camera/ndk/impl/ACameraManager.cpp
index f656008..ba2100c 100644
--- a/camera/ndk/impl/ACameraManager.cpp
+++ b/camera/ndk/impl/ACameraManager.cpp
@@ -335,7 +335,7 @@
return ACAMERA_ERROR_NOT_ENOUGH_MEMORY;
}
out->numCameras = numCameras;
- out->cameraIds = new const char*[numCameras] {nullptr};
+ out->cameraIds = new const char*[numCameras];
if (!out->cameraIds) {
ALOGE("Allocate memory for ACameraIdList failed!");
deleteCameraIdList(out);