I’m Trying to do:
printf("Provider: %s\n", Props->providerName);
where struct member (from external library) is:
char providerName[256];
causes core dump with gdb output of:
Program terminated with signal 11, Segmentation fault.
[New process 73950 ]
#0 0xfee22290 in strlen () from /lib/libc.so.1
I guess the char[] might not be null terminated, but what is the best solution?
Cheers!
edit: The structure I’m using is from an external library, and appears not to be null (I can successfully print another of its members char alias[256];
Use a maximum-width indicator whenever you can when using
%swith printf:If you still get a segfault, and Props is not
NULL, you probably have a clash between your headers and the library binaries. Suppose you have the new version of headers that define:but the library binaries are outdated, using the following definition:
If you now try to access
bazyou’ll get a segmentation fault, even though the other members work fine.(edit: added text from “if you get a segfault” to end of answer)