%
*/
-static char *EscapeParenthesis(const char *text)
+static char *EscapeParenthesis(const char *source)
{
char
- *buffer;
+ *destination;
register char
- *p;
+ *q;
- register ssize_t
- i;
+ register const char
+ *p;
size_t
- escapes;
+ length;
- escapes=0;
- buffer=AcquireString(text);
- p=buffer;
- for (i=0; i < (ssize_t) MagickMin(strlen(text),MagickPathExtent-escapes-1); i++)
+ assert(source != (const char *) NULL);
+ length=0;
+ for (p=source; *p != '\0'; p++)
{
- if ((text[i] == '(') || (text[i] == ')'))
+ if ((*p == '\\') || (*p == '(') || (*p == ')'))
{
- *p++='\\';
- escapes++;
+ if (~length < 1)
+ ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
+ length++;
}
- *p++=text[i];
+ length++;
+ }
+ destination=(char *) NULL;
+ if (~length >= (MagickPathExtent-1))
+ destination=(char *) AcquireQuantumMemory(length+MagickPathExtent,
+ sizeof(*destination));
+ if (destination == (char *) NULL)
+ ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
+ *destination='\0';
+ q=destination;
+ for (p=source; *p != '\0'; p++)
+ {
+ if ((*p == '\\') || (*p == '(') || (*p == ')'))
+ *q++='\\';
+ *q++=(*p);
}
- *p='\0';
- return(buffer);
+ *q='\0';
+ return(destination);
}
static MagickBooleanType RenderPostscript(Image *image,
length;
assert(source != (const char *) NULL);
- length=strlen(source);
+ length=0;
for (p=source; *p != '\0'; p++)
+ {
if ((*p == '\\') || (*p == escape))
{
if (~length < 1)
ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
length++;
}
+ length++;
+ }
destination=(char *) NULL;
if (~length >= (MagickPathExtent-1))
destination=(char *) AcquireQuantumMemory(length+MagickPathExtent,
continue;
hires_bounds=bounds;
}
- if ((fabs(hires_bounds.x2-hires_bounds.x1) >= MagickEpsilon) &&
+ if ((fabs(hires_bounds.x2-hires_bounds.x1) >= MagickEpsilon) &&
(fabs(hires_bounds.y2-hires_bounds.y1) >= MagickEpsilon))
{
/*
%
*/
-static char *EscapeParenthesis(const char *text)
+static char *EscapeParenthesis(const char *source)
{
+ char
+ *destination;
+
register char
- *p;
+ *q;
- register ssize_t
- i;
+ register const char
+ *p;
size_t
- escapes;
-
- static char
- buffer[MagickPathExtent];
+ length;
- escapes=0;
- p=buffer;
- for (i=0; i < (ssize_t) MagickMin(strlen(text),(MagickPathExtent-escapes-1)); i++)
+ assert(source != (const char *) NULL);
+ length=0;
+ for (p=source; *p != '\0'; p++)
{
- if ((text[i] == '(') || (text[i] == ')'))
+ if ((*p == '\\') || (*p == '(') || (*p == ')'))
{
- *p++='\\';
- escapes++;
+ if (~length < 1)
+ ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
+ length++;
}
- *p++=text[i];
+ length++;
+ }
+ destination=(char *) NULL;
+ if (~length >= (MagickPathExtent-1))
+ destination=(char *) AcquireQuantumMemory(length+MagickPathExtent,
+ sizeof(*destination));
+ if (destination == (char *) NULL)
+ ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
+ *destination='\0';
+ q=destination;
+ for (p=source; *p != '\0'; p++)
+ {
+ if ((*p == '\\') || (*p == '(') || (*p == ')'))
+ *q++='\\';
+ *q++=(*p);
}
- *p='\0';
- return(buffer);
+ *q='\0';
+ return(destination);
}
static size_t UTF8ToUTF16(const unsigned char *utf8,wchar_t *utf16)