jpilot icon indicating copy to clipboard operation
jpilot copied to clipboard

Plugin crash caused by deactivated functions provided in `libplugin.h`

Open CoSoCo opened this issue 10 months ago • 2 comments

The use of the following functions in a plugin cause it to crash:

void jp_pref_init(prefType prefs[], int count);
void jp_free_prefs(prefType prefs[], int count);

This is, because their implementation in prefs.c was deactivated since JPilot version 2.0.2. Please activate them again.

I also don't understand why the strings of the glob_prefs are initialised with the default values using the long switch ... case statement (from line 172 in prefs.c) are initialised with the default values instead of using the compact jp_pref_init() function. Take a look at how compactly I have solved this in JPilotMediaPlugin (from line 68) and line 945. It is also much more organised and clearer if the default strings are defined in the same assignment of the prefs array.

And they could be coded more compact :

void jp_pref_init(prefType prefs[], int count) {
   for (int i=0; i<count; i++) {
      prefs[i].svalue = strdup(prefs[i].svalue ? prefs[i].svalue : "");
      prefs[i].svalue_size = strlen(prefs[i].svalue)+1;
   }
}

void jp_free_prefs(prefType prefs[], int count) {
   for (int i=0; i<count; i++) {
      if (prefs[i].svalue) {
         free(prefs[i].svalue);
         prefs[i].svalue = NULL;
      }
   }
}

CoSoCo avatar Feb 28 '25 16:02 CoSoCo

I intend to reactivate the named routines in the next few days. Apparently they were deactivated erroneously.

Sorry for the inconvenience caused.

eklausme avatar Feb 28 '25 20:02 eklausme

Please release a DEB-package with this fix.

CoSoCo avatar Mar 09 '25 20:03 CoSoCo