segmentation fault - Fingerprint calls cause segfaults in c++ -


i'm trying write simple fingerprint scanning program in c++ using libfprint, intermittently segfaults when run. valgrind says error in call fp_enroll_finger consistent debugging, beyond have absolutely no idea causing error. of times program run fine, times seems consistently segfault period of time whenever program run? heres code:

#include <iostream>  extern "c" {     #include <libfprint/fprint.h> }  using namespace std;  fp_dev * fpdev; fp_print_data ** fpdata;  bool createdevice();  int main(int argc, char **argv) {     int r = fp_init();     if(r != 0)     {         return r;     }      while(createdevice())     {         cout << "scan right index finger" << endl;         int enrollstatus = fp_enroll_finger(fpdev, fpdata);          if(enrollstatus != 1)         {             cout << "bad scan" << endl;             fp_dev_close(fpdev);         }         else         {             cout << "good scan" << endl;             fp_print_data_save(fpdata[0], right_index);             break;         }     }      if(fpdev != null)     {         fp_dev_close(fpdev);     }      fp_exit();     return 0; }  bool createdevice() {     fp_dscv_dev ** listofdiscovereddevs;     fp_dscv_dev * discovereddevice;     listofdiscovereddevs = fp_discover_devs();     discovereddevice = listofdiscovereddevs[0];      if(discovereddevice != null)     {         cout << "device found" << endl;         fpdev = fp_dev_open(discovereddevice);     }     else     {         cout << "no device found" << endl;         return false;     }      fp_dscv_devs_free(listofdiscovereddevs);     return true; } 

you need define fpdev , fpdata as:

fp_dev * fpdev; fp_print_data * fpdata; 

and use them as:

fp_enroll_finger(&fpdev, &fpdata); 

also don't forget free fpdata when no longer need fp_print_data_free

fp_dev * fpdev; fp_print_data ** fpdata; 

will create 2 uninitialised pointers pointing random memory location , leading segfault once fp_enroll_finger attempt acces location. checking fp_enroll_finger return value can useful well.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -