From d8bcdf1138d422274359da8d775514dee936495a Mon Sep 17 00:00:00 2001 From: Cristy Date: Sun, 20 Jan 2019 10:02:42 -0500 Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/1455 --- MagickCore/animate.c | 3 +- MagickCore/display.c | 3 +- MagickCore/locale.c | 70 +++++++++++++++++++++++++++++++++++++++-- MagickCore/locale_.h | 4 ++- MagickCore/nt-feature.c | 4 +-- MagickCore/token.c | 7 ++--- MagickCore/vms.c | 2 +- coders/fits.c | 2 +- coders/meta.c | 6 ++-- 9 files changed, 85 insertions(+), 16 deletions(-) diff --git a/MagickCore/animate.c b/MagickCore/animate.c index c66d08ef0..e79715c03 100644 --- a/MagickCore/animate.c +++ b/MagickCore/animate.c @@ -1575,7 +1575,8 @@ MagickExport Image *XAnimateImages(Display *display, resource_info,&windows->context); (void) CloneString(&class_hints->res_name,resource_info->client_name); (void) CloneString(&class_hints->res_class,resource_info->client_name); - class_hints->res_class[0]=(char) toupper((int) class_hints->res_class[0]); + class_hints->res_class[0]=(char) LocaleUppercase((int) + class_hints->res_class[0]); manager_hints->flags=InputHint | StateHint; manager_hints->input=MagickFalse; manager_hints->initial_state=WithdrawnState; diff --git a/MagickCore/display.c b/MagickCore/display.c index 2dee778ad..457490424 100644 --- a/MagickCore/display.c +++ b/MagickCore/display.c @@ -14628,7 +14628,8 @@ MagickExport Image *XDisplayImage(Display *display,XResourceInfo *resource_info, resource_info,&windows->context); (void) CloneString(&class_hints->res_name,resource_info->client_name); (void) CloneString(&class_hints->res_class,resource_info->client_name); - class_hints->res_class[0]=(char) toupper((int) class_hints->res_class[0]); + class_hints->res_class[0]=(char) LocaleUppercase((int) + class_hints->res_class[0]); manager_hints->flags=InputHint | StateHint; manager_hints->input=MagickFalse; manager_hints->initial_state=WithdrawnState; diff --git a/MagickCore/locale.c b/MagickCore/locale.c index d44dfe86f..f9f4b52c0 100644 --- a/MagickCore/locale.c +++ b/MagickCore/locale.c @@ -1499,7 +1499,40 @@ MagickExport void LocaleLower(char *string) assert(string != (char *) NULL); for (q=string; *q != '\0'; q++) - *q=(char) tolower((int) *q); + *q=(char) LocaleLowercase((int) *q); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% L o c a l e L o w e r c a s e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% LocaleLowercase() convert to uppercase. +% +% The format of the LocaleLowercase method is: +% +% void LocaleLowercase(const int c) +% +% A description of each parameter follows: +% +% o If c is a uppercase letter, return its lowercase equivalent. +% +*/ +MagickExport int LocaleLowercase(const int c) +{ + locale_t + locale; + + locale=AcquireCLocale(); + if (locale == (locale_t) NULL) + return(tolower(c)); + return(tolower_l(c,locale)); } /* @@ -1606,7 +1639,40 @@ MagickExport void LocaleUpper(char *string) assert(string != (char *) NULL); for (q=string; *q != '\0'; q++) - *q=(char) toupper((int) *q); + *q=(char) LocaleUppercase((int) *q); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% L o c a l e U p p e r c a s e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% LocaleUppercase() convert to uppercase. +% +% The format of the LocaleUppercase method is: +% +% void LocaleUppercase(const int c) +% +% A description of each parameter follows: +% +% o If c is a lowercase letter, return its uppercase equivalent. +% +*/ +MagickExport int LocaleUppercase(const int c) +{ + locale_t + locale; + + locale=AcquireCLocale(); + if (locale == (locale_t) NULL) + return(toupper(c)); + return(toupper_l(c,locale)); } /* diff --git a/MagickCore/locale_.h b/MagickCore/locale_.h index 927dc25ec..57d61d599 100644 --- a/MagickCore/locale_.h +++ b/MagickCore/locale_.h @@ -53,8 +53,10 @@ extern MagickExport double extern MagickExport int LocaleCompare(const char *,const char *) magick_attribute((__pure__)), + LocaleLowercase(const int), LocaleNCompare(const char *,const char *,const size_t) - magick_attribute((__pure__)); + magick_attribute((__pure__)), + LocaleUppercase(const int); extern MagickExport LinkedListInfo *DestroyLocaleOptions(LinkedListInfo *), diff --git a/MagickCore/nt-feature.c b/MagickCore/nt-feature.c index 68c11f2de..0f756ed61 100644 --- a/MagickCore/nt-feature.c +++ b/MagickCore/nt-feature.c @@ -96,8 +96,8 @@ MagickExport MagickBooleanType NTIsMagickConflict(const char *magick) assert(magick != (char *) NULL); if (strlen(magick) > 1) return(MagickFalse); - status=(GetLogicalDrives() & (1 << ((toupper((int) (*magick)))-'A'))) != 0 ? - MagickTrue : MagickFalse; + status=(GetLogicalDrives() & (1 << ((LocaleUppercase((int) + (*magick)))-'A'))) != 0 ? MagickTrue : MagickFalse; return(status); } diff --git a/MagickCore/token.c b/MagickCore/token.c index c44b43050..ca98b9856 100644 --- a/MagickCore/token.c +++ b/MagickCore/token.c @@ -541,8 +541,7 @@ MagickExport MagickBooleanType GlobExpression(const char *expression, { if (case_insensitive != MagickFalse) { - if (tolower((int) GetUTFCode(expression)) != - tolower((int) GetUTFCode(pattern))) + if (LocaleLowercase((int) GetUTFCode(expression)) != LocaleLowercase((int) GetUTFCode(pattern))) { done=MagickTrue; break; @@ -815,12 +814,12 @@ static void StoreToken(TokenInfo *token_info,char *string, { case 1: { - string[i]=(char) toupper(c); + string[i]=(char) LocaleUppercase(c); break; } case 2: { - string[i]=(char) tolower(c); + string[i]=(char) LocaleLowercase(c); break; } default: diff --git a/MagickCore/vms.c b/MagickCore/vms.c index 8380bb85c..8e4b41758 100644 --- a/MagickCore/vms.c +++ b/MagickCore/vms.c @@ -196,7 +196,7 @@ struct dirent *readdir(DIR *directory) buffer[sizeof(buffer)-1]='\0'; for (p=buffer; *p; p++) if (isupper((int) ((unsigned char) *p))) - *p=tolower(*p); + *p=LocaleLowercase(*p); /* Skip any directory component and just copy the name. */ diff --git a/coders/fits.c b/coders/fits.c index e71020fab..f342423f1 100644 --- a/coders/fits.c +++ b/coders/fits.c @@ -331,7 +331,7 @@ static Image *ReadFITSImage(const ImageInfo *image_info, { if (isspace((int) ((unsigned char) keyword[i])) != 0) break; - keyword[i]=tolower((int) ((unsigned char) keyword[i])); + keyword[i]=LocaleLowercase((int) ((unsigned char) keyword[i])); } keyword[i]='\0'; count=ReadBlob(image,72,(unsigned char *) value); diff --git a/coders/meta.c b/coders/meta.c index 2e90625fa..cbdeddeb0 100644 --- a/coders/meta.c +++ b/coders/meta.c @@ -179,10 +179,10 @@ static int stringnicmp(const char *p,const char *q,size_t n) break; i=(*p); if (islower(i)) - i=toupper(i); + i=LocaleUppercase(i); j=(*q); if (islower(j)) - j=toupper(j); + j=LocaleUppercase(j); if (i != j) break; n--; @@ -191,7 +191,7 @@ static int stringnicmp(const char *p,const char *q,size_t n) p++; q++; } - return(toupper((int) *p)-toupper((int) *q)); + return(LocaleUppercase((int) *p)-LocaleUppercase((int) *q)); } static size_t convertHTMLcodes(char *s) -- 2.40.0