Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when calling mcc118_open() after setlocale() #5

Closed
mattrust opened this issue Mar 24, 2019 · 1 comment
Closed

Crash when calling mcc118_open() after setlocale() #5

mattrust opened this issue Mar 24, 2019 · 1 comment

Comments

@mattrust
Copy link

mattrust commented Mar 24, 2019

Hi,

I have a crash when I call mcc118_open() after setlocale().

#include <daqhats/daqhats.h>
#include <locale.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
printf("locale at program start %s\n", setlocale(LC_ALL, NULL));

mcc118_open(0); // calling before setlocale() works
mcc118_close(0);

// That's what gtk_init() is doing according
// to the documentation of gtk_disable_setlocale()
setlocale (LC_ALL, "");
printf("locale after setlocale() %s\n", setlocale (LC_ALL, NULL));

mcc118_open(0); // calling after setlocale() segfaults
mcc118_close(0);

return 0;

}

The 2nd call of mcc118_open() crashes.

I have built libdaqhats with -O0 to get better backtraces:

#0 0x76f82d14 in _parse_factory_data (root=0x0, data=0x22a08) at mcc118.c:689
#1 0x76f83a88 in mcc118_open (address=0 '\000') at mcc118.c:1143
#2 0x000106f8 in main (argc=1, argv=0x7effefe4) at test.c:17

Crash happens in line
if ((root->type != cJSON_Object) ||

because root is NULL.

The crash doesn't happen anymore if I do
export LC_ALL=C in the console.

I have built the example like this
gcc -Wall -O0 -g test.c -ldaqhats

My locale is de_DE.UTF-8

@nwright-mcc
Copy link
Collaborator

The cJSON conversion of the EEPROM data is failing due to the locale changing to one that uses commas as the decimal point character. Adding -DENABLE_LOCALES=Off to the compile options fixes the issue, and I will do more checking on the returned pointer. This will be added to the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants