From: anthony Date: Sun, 13 May 2012 01:54:53 +0000 (+0000) Subject: Refactor of main InterpretImageProperties() X-Git-Tag: 7.0.1-0~5603 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=104f8932a48379d3355160642b3de6f0611a7d19;p=imagemagick Refactor of main InterpretImageProperties() --- diff --git a/MagickCore/property.c b/MagickCore/property.c index 7eb1c2f0e..fb8325279 100644 --- a/MagickCore/property.c +++ b/MagickCore/property.c @@ -2958,7 +2958,7 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info, p++; if (*p != '-' && IfMagickFalse(IsPathAccessible(p)) ) { (void) ThrowMagickException(exception,GetMagickModule(), - OptionError,"UnableToAcessPath","%s",p); + OptionError,"UnableToAccessPath","%s",p); return((char *) NULL); } return(FileToString(p,~0,exception)); @@ -3013,11 +3013,11 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info, } continue; /* never reached! */ case '&': - if (LocaleNCompare("<",p+1,4) != 0) + if (LocaleNCompare("<",p,4) == 0) *q++='<', p+=3; - else if (LocaleNCompare(">",p+1,4) != 0) + else if (LocaleNCompare(">",p,4) == 0) *q++='>', p+=3; - else if (LocaleNCompare("&",p+1,5) != 0) + else if (LocaleNCompare("&",p,5) == 0) *q++='&', p+=4; else *q++=(*p); @@ -3028,28 +3028,29 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info, *q++=(*p); /* any thing else is 'as normal' */ continue; } + p++; /* advance beyond the percent */ /* Doubled Percent */ - if ( *(p+1) == '%' ) { + if ( *p == '%' ) { *q++=(*p); - p++; - } + continue; + } /* Single letter escapes */ - if ( *(p+1) != '[' ) { + if ( *p != '[' ) { const char *value; /* But only if not preceeded by a number! */ if ( IfMagickTrue(number) ) { - *q++=(*p); /* do NOT substitute the percent */ + *q++='%'; /* do NOT substitute the percent */ + p--; /* back up one */ continue; } - p++; value=GetMagickPropertyLetter(image_info,image,*p, exception); if (value != (char *) NULL) { length=strlen(value); @@ -3058,10 +3059,8 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info, extent+=length; interpret_text=(char *) ResizeQuantumMemory(interpret_text, extent+MaxTextExtent,sizeof(*interpret_text)); - if (interpret_text == (char *) NULL) { - value=DestroyString((char *)value); + if (interpret_text == (char *) NULL) return((char *)NULL); - } q=interpret_text+strlen(interpret_text); } (void) CopyMagickString(q,value,extent); @@ -3091,7 +3090,7 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info, depth; /* get the string framed by the %[...] */ - p+=2; /* advance p to just inside the opening brace */ + p++; /* advance p to just inside the opening brace */ depth=1; if ( *p == ']' ) { (void) ThrowMagickException(exception,GetMagickModule(), @@ -3124,12 +3123,13 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info, pattern[64] = '\0'; } (void) ThrowMagickException(exception,GetMagickModule(), - OptionError,"UnbalancedBraces","\"%%[%s]\"",pattern); - break; /* exit loop */ + OptionError,"UnbalancedBraces","\"%%[%s\"",pattern); + interpret_text=DestroyString(interpret_text); + return((char *)NULL); } /* - Special Properity Prefixes + Special Property Prefixes such as: %[exif:...] %[fx:...] %[pixel:...] Otherwise a free-form properity string */ @@ -3197,10 +3197,8 @@ MagickExport char *InterpretImageProperties(const ImageInfo *image_info, extent+=length; interpret_text=(char *) ResizeQuantumMemory(interpret_text, extent+MaxTextExtent,sizeof(*interpret_text)); - if (interpret_text == (char *) NULL) { - value=DestroyString((char *)value); + if (interpret_text == (char *) NULL) return((char *)NULL); - } q=interpret_text+strlen(interpret_text); } (void) CopyMagickString(q,value,extent); @@ -3358,7 +3356,7 @@ MagickExport void ResetImagePropertyIterator(const Image *image) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% SetImageProperty() saves teh given string value either to specific known +% SetImageProperty() saves the given string value either to specific known % attribute or to a freeform properity string. % % Attempting to set a properity that is normally calculated will produce diff --git a/MagickCore/string.c b/MagickCore/string.c index 5d18b889b..948ed1db5 100644 --- a/MagickCore/string.c +++ b/MagickCore/string.c @@ -99,11 +99,13 @@ static const unsigned char % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% AcquireString() allocates memory for a string and copies the source string -% to that memory location (and returns it). +% AcquireString() returns an new extented string, containing a clone of the +% given string. % -% The returned string shoud be freed using DestoryString() or -% RelinquishMagickMemory() when finished. +% An extended string is the string length, plus an extra MaxTextExtent space +% to allow for the string to be activally worked on. +% +% The returned string shoud be freed using DestoryString(). % % The format of the AcquireString method is: % @@ -194,7 +196,8 @@ MagickExport StringInfo *AcquireStringInfo(const size_t length) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% BlobToStringInfo() returns the contents of a blob as a string. +% BlobToStringInfo() returns the contents of a blob as a StringInfo structure +% with MaxTextExtent extra space. % % The format of the BlobToStringInfo method is: % @@ -238,16 +241,15 @@ MagickExport StringInfo *BlobToStringInfo(const void *blob,const size_t length) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% CloneString() allocates memory for the destination string and copies -% the source string to that memory location. -% -% If source is a NULL pointer the destination will also be set to a NULL -% point (any existing string is freed). Otherwise the memory is allocated -% (or resized) and the source string copied into it. +% CloneString() replaces or frees the destination string to make it +% a clone of the input string plus MaxTextExtent more space so the string may +% be worked on on. % -% A pointer to the copy of the source string, or NULL is returned. +% If source is a NULL pointer the destination string will be freed and set to +% a NULL pointer. A pointer to the stored in the destination is also returned. % -% Free the string using DestoryString(). +% When finished the non-NULL string should be freed using DestoryString() +% or using CloneString() with a NULL pointed for the source. % % The format of the CloneString method is: % @@ -669,11 +671,11 @@ MagickExport StringInfo *ConfigureFileToStringInfo(const char *filename) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -% ConstantString() allocates memory for a string and copies the source string -% to that memory location (and returns it). Use it for strings that you do -% do not expect to change over its lifetime. +% ConstantString() allocates exactly the needed memory for a string and +% copies the source string to that memory location. A NULL string pointer +% will allocate an empty string containing just the NUL character. % -% When finished free the string using DestoryString(). +% When finished the string should be freed using DestoryString() % % The format of the ConstantString method is: % diff --git a/MagickCore/utility.c b/MagickCore/utility.c index f17056da1..d44808332 100644 --- a/MagickCore/utility.c +++ b/MagickCore/utility.c @@ -1169,6 +1169,9 @@ MagickExport MagickBooleanType GetPathAttributes(const char *path, % GetPathComponent() returns the parent directory name, filename, basename, or % extension of a file path. % +% The component string pointed to must have at least MaxTextExtent space +% for the results to be stored. +% % The format of the GetPathComponent function is: % % GetPathComponent(const char *path,PathType type,char *component) diff --git a/config/english.xml b/config/english.xml index 63c671791..e4b333c13 100644 --- a/config/english.xml +++ b/config/english.xml @@ -331,9 +331,6 @@ - - unknown image property - insufficient image data in file @@ -722,7 +719,7 @@ two or more images required - + unable to access file path @@ -951,6 +948,9 @@ no such element in list + + unknown image property + unrecognized color diff --git a/config/francais.xml b/config/francais.xml index 86632ffa0..616ea39b2 100644 --- a/config/francais.xml +++ b/config/francais.xml @@ -309,9 +309,6 @@ facteur d'échantillonnage inattendu - - image propriété non reconnus - type de motif inconnu @@ -716,7 +713,7 @@ deux ou plusieurs images nécessaires - + incapables d'accéder chemin du fichier @@ -942,6 +939,9 @@ élément absent de la liste + + image propriété non reconnus + couleur non reconnue