strcasestr() called, but some platforms don't have it

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Locked
rkl
Posts: 1
Joined: 2019-11-14T04:14:59-07:00
Authentication code: 1152

strcasestr() called, but some platforms don't have it

Post by rkl »

I've been building ImageMagick 7.0.9-3 on Itanium HP-UX 11.31 with HP's ANSI C/C++ compiler.
HP-UX's C library doesn't have strcasestr(), so config/config.h contains:

/* #undef HAVE_STRCASESTR */

However, a check for HAVE_STRCASESTR is never made in the code, so calls to strcasestr() fail
in MagickCore/profile.c, MagickCore/color.c and coders/ps.c.

There is an implementation of strcasestr() shipped with ImageMagick in MagickCore/nt-base.h, but as
the name implies, this is only fully included for the Windows platform.

I fixed it in HP-UX by copying that strcasestr() function from MagickCore/nt-base.h to MagickCore/string_.h
so that the code looked like this in MagickCore/string_.h:

#ifndef HAVE_STRCASESTR

extern size_t strlen(const char *s);
extern int toupper(int c);

static inline char *strcasestr(const char *haystack,const char *needle)
{
...
return(NULL);
}
#endif /* HAVE_STRCASESTR */

It's probably not the "most correct" way of doing things (also note I had to add the two extern statements to keep the HP compiler happy), but it worked for me.

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: strcasestr() called, but some platforms don't have it

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ https://www.imagemagick.org/download/beta/ by sometime tomorrow.

Locked