Bug 129610 - digikam: unsupported initialization of CameraList object
Summary: digikam: unsupported initialization of CameraList object
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Unclassified
Component: Import-Gphoto2 (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-21 22:20 UTC by Achim Bohnet
Modified: 2017-08-16 06:13 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 0.9.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Achim Bohnet 2006-06-21 22:20:27 UTC
Version:           0.8.2-rc1 (using KDE 3.5.2, Kubuntu Package 4:3.5.2-0ubuntu18 dapper)
Compiler:          Target: i486-linux-gnu
OS:                Linux (i686) release 2.6.15-25-686

While checking the diff between 2.1.6 and 2.2 headers I stumpled
over this:

+/* Usage pattern for CameraList for users external of
+ * libgphoto2, such as libgphoto2 frontends:
+ *
+ *    CameraList *list;
+ *    gp_list_new (&list);
+ *    init_list_somehow (list);
+ *    for (i=0; i < gp_list_count(list); i++) {
+ *        char *name, *value;
+ *        gp_list_get_name (list, i, &name);
+ *        gp_list_get_name (list, i, &value);
+ *        do_something_with (name, value);
+ *    }
+ *    gp_list_free (list);
+ *
+ * Please do NOT directly instantiate a CameraList object like this:
+ *               CameraList foo;     // DO NOT DO THIS
+ * Please do NOT directly access the structure members like this:
+ *               list->entry[i].name // DO NOT DO THIS
+ */

Grep on sources in trunk:

$ grep -n CameraList cameragui/*
cameragui/gpcamera.cpp:295:    CameraList *clist;
cameragui/gpcamera.cpp:337:    CameraList *clist;
cameragui/gpcamera.cpp:382:    CameraList *clist;
cameragui/gpcamera.cpp:852:    CameraList camList;
                               ^^^^^^^^^^^^^^^^^^  that's a DO NOT DO THIS

Last but not least:

$ grep -n clist- cameragui/* | echo good
good

;)

Achim
Comment 1 caulier.gilles 2006-06-21 23:07:28 UTC
SVN commit 553726 by cgilles:

digikam from trunk : fix initialization of CameraList object
CCBUGS: 129610


 M  +25 -18    gpcamera.cpp  
 M  +1 -2      gpcamera.h  


--- trunk/extragear/graphics/digikam/utilities/cameragui/gpcamera.cpp #553725:553726
@@ -41,6 +41,10 @@
 #include <qdom.h>
 #include <qfile.h>
 
+// KDE includes.
+
+#include <kdebug.h>
+
 // Local includes.
 
 #include "gpcamera.h"
@@ -782,7 +786,7 @@
     if ( count < 0) 
     {
         gp_context_unref( context );
-        qWarning("failed to get list of cameras");
+        kdDebug() << "failed to get list of cameras!" << endl;
         return;
     }
     else 
@@ -849,39 +853,42 @@
 
 int GPCamera::autoDetect(QString& model, QString& port)
 {
-    CameraList camList;
+    CameraList          *camList;
     CameraAbilitiesList *abilList;
-    GPPortInfoList *infoList;
-    const char *camModel_, *camPort_;
-    GPContext *context;
+    GPPortInfoList      *infoList;
+    const char          *camModel_, *camPort_;
+    GPContext           *context;
 
     context = gp_context_new();
+    gp_list_new(&camList);
 
-    gp_abilities_list_new (&abilList);
-    gp_abilities_list_load (abilList, context);
-    gp_port_info_list_new (&infoList);
-    gp_port_info_list_load (infoList);
-    gp_abilities_list_detect (abilList, infoList, &camList, context);
-    gp_abilities_list_free (abilList);
-    gp_port_info_list_free (infoList);
+    gp_abilities_list_new(&abilList);
+    gp_abilities_list_load(abilList, context);
+    gp_port_info_list_new(&infoList);
+    gp_port_info_list_load(infoList);
+    gp_abilities_list_detect(abilList, infoList, camList, context);
+    gp_abilities_list_free(abilList);
+    gp_port_info_list_free(infoList);
 
-    gp_context_unref( context );
+    gp_context_unref(context);
 
-    int count = gp_list_count (&camList);
+    int count = gp_list_count(camList);
 
-    if (count<=0) 
+    if (count <= 0) 
     {
+        gp_list_free(camList);
         return -1;
     }
 
-    for (int i = 0; i < count; i++) 
+    for (int i = 0 ; i < count ; i++) 
     {
-        gp_list_get_name  (&camList, i, &camModel_);
-        gp_list_get_value (&camList, i, &camPort_);
+        gp_list_get_name (camList, i, &camModel_);
+        gp_list_get_value(camList, i, &camPort_);
     }
 
     model = camModel_;
     port  = camPort_;
+    gp_list_free(camList);
 
     return 0;
 }
--- trunk/extragear/graphics/digikam/utilities/cameragui/gpcamera.h #553725:553726
@@ -93,8 +93,7 @@
     
     static void getSupportedCameras(int& count, QStringList& clist);
     static void getSupportedPorts(QStringList& plist);
-    static void getCameraSupportedPorts(const QString& model,
-                                        QStringList& plist);
+    static void getCameraSupportedPorts(const QString& model, QStringList& plist);
     static int  autoDetect(QString& model, QString& port);
     
 
Comment 2 caulier.gilles 2006-06-21 23:31:38 UTC
SVN commit 553732 by cgilles:

digikam from stable : fix initialization of CameraList object
CCBUGS: 129610


 M  +57 -36    gpcamera.cpp  


--- branches/stable/extragear/graphics/digikam/utilities/cameragui/gpcamera.cpp #553731:553732
@@ -18,40 +18,57 @@
  * 
  * ============================================================ */
 
+// C Ansi includes.
+
+extern "C" 
+{
+#include <stdio.h>
+#include <gphoto2.h>
+}
+
+// C++ includes.
+
+#include <iostream>
+
+// Qt includes.
+
 #include <qstring.h>
 #include <qstringlist.h>
 #include <qimage.h>
 #include <qdom.h>
 #include <qfile.h>
 
-#include <iostream>
+// KDE includes.
 
-extern "C" {
-#include <stdio.h>
-#include <gphoto2.h>
-}
+#include <kdebug.h>
 
+// Local includes.
+
 #include "gpcamera.h"
 
 class GPCameraPrivate
 {
 public:
 
-    Camera *camera;
-    CameraAbilities cameraAbilities;
+    GPCameraPrivate()
+    {
+        camera = 0;
+    }
 
-    QString model;
-    QString port;
-    QString globalPath;
-
-    bool cameraInitialized;
+    bool             cameraInitialized;
     
-    bool thumbnailSupport;
-    bool deleteSupport;
-    bool uploadSupport;
-    bool mkDirSupport;
-    bool delDirSupport;
+    bool             thumbnailSupport;
+    bool             deleteSupport;
+    bool             uploadSupport;
+    bool             mkDirSupport;
+    bool             delDirSupport;
     
+    QString          model;
+    QString          port;
+    QString          globalPath;
+
+    Camera          *camera;
+    CameraAbilities  cameraAbilities;
 };
 
 class GPStatus
@@ -802,38 +819,42 @@
 
 int GPCamera::autoDetect(QString& model, QString& port)
 {
-    CameraList camList;
+    CameraList          *camList;
     CameraAbilitiesList *abilList;
-    GPPortInfoList *infoList;
-    const char *camModel_, *camPort_;
-    GPContext *context;
+    GPPortInfoList      *infoList;
+    const char          *camModel_, *camPort_;
+    GPContext           *context;
 
-    context = gp_context_new ();
+    context = gp_context_new();
+    gp_list_new(&camList);
 
-    gp_abilities_list_new (&abilList);
-    gp_abilities_list_load (abilList, context);
-    gp_port_info_list_new (&infoList);
-    gp_port_info_list_load (infoList);
-    gp_abilities_list_detect (abilList, infoList,
-                              &camList, context);
-    gp_abilities_list_free (abilList);
-    gp_port_info_list_free (infoList);
+    gp_abilities_list_new(&abilList);
+    gp_abilities_list_load(abilList, context);
+    gp_port_info_list_new(&infoList);
+    gp_port_info_list_load(infoList);
+    gp_abilities_list_detect(abilList, infoList, camList, context);
+    gp_abilities_list_free(abilList);
+    gp_port_info_list_free(infoList);
 
-    gp_context_unref( context );
+    gp_context_unref(context);
 
-    int count = gp_list_count (&camList);
+    int count = gp_list_count(camList);
 
-    if (count<=0) {
+    if (count <= 0) 
+    {
+        gp_list_free(camList);
         return -1;
     }
 
-    for (int i = 0; i < count; i++) {
-        gp_list_get_name  (&camList, i, &camModel_);
-        gp_list_get_value (&camList, i, &camPort_);
+    for (int i = 0 ; i < count ; i++) 
+    {
+        gp_list_get_name (camList, i, &camModel_);
+        gp_list_get_value(camList, i, &camPort_);
     }
 
     model = camModel_;
     port  = camPort_;
+    gp_list_free(camList);
 
     return 0;
 }
Comment 3 caulier.gilles 2006-06-21 23:54:24 UTC
Fixed in svn. Closed

Gilles