usershape_t *gvusershape_find(char *name)
{
- usershape_t probe;
+ usershape_t probe, *us;
+
+ assert(name);
+ assert(name[0]);
if (!ImageDict)
return NULL;
probe.name = name;
- return (dtsearch(ImageDict, &probe));
+ us = dtsearch(ImageDict, &probe);
+ return us;
}
#define MAX_USERSHAPE_FILES_OPEN 50
assert(us);
assert(us->name);
+ assert(us->name[0]);
if (us->f)
fseek(us->f, 0, SEEK_SET);
else {
- if ((fn = safefile(us->name))) {
+ if (! (fn = safefile(us->name))) {
+ agerr(AGWARN, "Filename \"%s\" is unsafe\n", us->name);
+ return FALSE;
+ }
#ifndef WIN32
- us->f = fopen(fn, "r");
+ us->f = fopen(fn, "r");
#else
- us->f = fopen(fn, "rb");
+ us->f = fopen(fn, "rb");
#endif
- if (us->f == NULL) {
- agerr(AGWARN, "%s while opening %s\n", strerror(errno), fn);
- return FALSE;
- }
- if (usershape_files_open_cnt >= MAX_USERSHAPE_FILES_OPEN)
- us->nocache = TRUE;
- else
- usershape_files_open_cnt++;
+ if (us->f == NULL) {
+ agerr(AGWARN, "%s while opening %s\n", strerror(errno), fn);
+ return FALSE;
}
+ if (usershape_files_open_cnt >= MAX_USERSHAPE_FILES_OPEN)
+ us->nocache = TRUE;
+ else
+ usershape_files_open_cnt++;
}
+ assert(us->f);
return TRUE;
}
{
usershape_t *us;
+ assert(name);
+
if (!ImageDict)
ImageDict = dtopen(&ImageDictDisc, Dttree);
if (!gvusershape_file_access(us))
return NULL;
+ assert(us->f);
+
switch(imagetype(us)) {
case FT_NULL:
if (!(us->data = (void*)find_user_shape(us->name)))
default:
break;
}
+ gvusershape_file_release(us);
dtinsert(ImageDict, us);
+ return us;
}
-
gvusershape_file_release(us);
-
return us;
}
static cairo_status_t
reader (void *closure, unsigned char *data, unsigned int length)
{
- if ((FILE *)closure == NULL)
- return CAIRO_STATUS_READ_ERROR;
+ assert(closure);
if (length == fread(data, 1, length, (FILE *)closure)
|| feof((FILE *)closure))
return CAIRO_STATUS_SUCCESS;
assert(job);
assert(us);
assert(us->name);
+ assert(us->name[0]);
if (us->data) {
if (us->datafree == cairo_freeimage)
if (!surface) { /* read file into cache */
if (!gvusershape_file_access(us))
return NULL;
+ assert(us->f);
switch (us->type) {
#ifdef CAIRO_HAS_PNG_FUNCTIONS
case FT_PNG:
cairo_t *cr = (cairo_t *) job->context; /* target context */
cairo_surface_t *surface; /* source surface */
+ assert(job);
+ assert(us);
+ assert(us->name);
+ assert(us->name[0]);
+
surface = cairo_loadimage(job, us);
if (surface) {
cairo_save(cr);