Home   Manual

Compilation of Avogadro git v f6fe3b7


#1

Hi all,

I have been trying to compile the latest version on my old Mac (snowleopard 10.6.8).
My compiler (gcc 4.7.3 in Fink) lacks “strnlen” for some obscure reason.
I finally succeeded to by adding the following code (taken from gnuplot 5.0.0) in “elements.c”:

“//from gnuplot
#ifndef HAVE_STRNLEN
size_t
strnlen(const char *str, size_t n)
{
const char * stop = (char *)memchr(str, ‘\0’, n);
return stop ? stop - str : n;
}
#endif
//tentative”

There may be better ways …

Regards,

Louis


#2

Actually you can just replace:

size_t strl = strnlen(element->name, sizeof(element->name));

with:

element->name[sizeof(element->name)-1] = ‘\0’;
size_t strl = strlen(element->name);

I’ll do this in future versions of libmsym.

Technically this function is part of POSIX.1-2008, but I’ve seen it cause some issues with gcc compilers on OS X since it used to be a gnu extension.

Worked in computer security before, so I use strnlen out of habit to avoid potential buffer overflows.

/Marcus

On 02 Sep 2015, at 18:01, Louis Ricard [email protected] wrote:

Hi all,

I have been trying to compile the latest version on my old Mac (snowleopard 10.6.8).
My compiler (gcc 4.7.3 in Fink) lacks “strnlen” for some obscure reason.
I finally succeeded to by adding the following code (taken from gnuplot 5.0.0) in “elements.c”:

“//from gnuplot
#ifndef HAVE_STRNLEN
size_t
strnlen(const char *str, size_t n)
{
const char * stop = (char *)memchr(str, ‘\0’, n);
return stop ? stop - str : n;
}
#endif
//tentative”

There may be better ways …

Regards,

Louis


Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140


Avogadro-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/avogadro-devel