AVFoundation: fix crash when no camera is available on the system.
authorYoann Lopes <yoann.lopes@digia.com>
Fri, 7 Mar 2014 13:15:13 +0000 (14:15 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 7 Mar 2014 13:59:13 +0000 (14:59 +0100)
Change-Id: I0b473babae4d1fae605667957deca21ba1dc0c09
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
src/plugins/avfoundation/camera/avfvideodevicecontrol.mm

index d049859..03736c3 100644 (file)
@@ -66,7 +66,7 @@ int AVFVideoDeviceControl::deviceCount() const
 QString AVFVideoDeviceControl::deviceName(int index) const
 {
     const QList<QByteArray> &devices = AVFCameraSession::availableCameraDevices();
-    if (index >= devices.count())
+    if (index < 0 || index >= devices.count())
         return QString();
 
     return QString::fromUtf8(devices.at(index));
@@ -75,7 +75,7 @@ QString AVFVideoDeviceControl::deviceName(int index) const
 QString AVFVideoDeviceControl::deviceDescription(int index) const
 {
     const QList<QByteArray> &devices = AVFCameraSession::availableCameraDevices();
-    if (index >= devices.count())
+    if (index < 0 || index >= devices.count())
         return QString();
 
     return AVFCameraSession::cameraDeviceInfo(devices.at(index)).description;
@@ -93,7 +93,9 @@ int AVFVideoDeviceControl::selectedDevice() const
 
 void AVFVideoDeviceControl::setSelectedDevice(int index)
 {
-    if (index != m_selectedDevice) {
+    if (index >= 0 &&
+            index < deviceCount() &&
+            index != m_selectedDevice) {
         m_dirty = true;
         m_selectedDevice = index;
         Q_EMIT selectedDeviceChanged(index);