From caa910e492e4d15208f3d179021687c25a84f36e Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Wed, 29 Jun 2005 18:46:53 +0000 Subject: Import Xcursor 1.1.4 from freedesktop.org xlibs tree. --- src/cursor.c | 1 + src/display.c | 1 + src/file.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++----- src/library.c | 25 ++++++++++++ src/xcursorint.h | 1 + src/xlib.c | 26 ++++++++++++- 6 files changed, 157 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/cursor.c b/src/cursor.c index fc92924..16c65ea 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -1,4 +1,5 @@ /* + * $Id$ * * Copyright © 2002 Keith Packard * diff --git a/src/display.c b/src/display.c index a2af97d..73fb8b3 100644 --- a/src/display.c +++ b/src/display.c @@ -1,4 +1,5 @@ /* + * $Id$ * * Copyright © 2002 Keith Packard * diff --git a/src/file.c b/src/file.c index 84a4a8a..de17004 100644 --- a/src/file.c +++ b/src/file.c @@ -1,4 +1,5 @@ /* + * $Id$ * * Copyright © 2002 Keith Packard * @@ -46,7 +47,8 @@ XcursorImageCreate (int width, int height) void XcursorImageDestroy (XcursorImage *image) { - free (image); + if (image) + free (image); } XcursorImages * @@ -69,6 +71,9 @@ XcursorImagesDestroy (XcursorImages *images) { int n; + if (!images) + return; + for (n = 0; n < images->nimage; n++) XcursorImageDestroy (images->images[n]); if (images->name) @@ -79,10 +84,16 @@ XcursorImagesDestroy (XcursorImages *images) void XcursorImagesSetName (XcursorImages *images, const char *name) { - char *new = malloc (strlen (name) + 1); + char *new; + + if (!images || !name) + return; + + new = malloc (strlen (name) + 1); if (!new) return; + strcpy (new, name); if (images->name) free (images->name); @@ -110,7 +121,8 @@ XcursorCommentCreate (XcursorUInt comment_type, int length) void XcursorCommentDestroy (XcursorComment *comment) { - free (comment); + if (!comment) + free (comment); } XcursorComments * @@ -132,6 +144,9 @@ XcursorCommentsDestroy (XcursorComments *comments) { int n; + if (!comments) + return; + for (n = 0; n < comments->ncomment; n++) XcursorCommentDestroy (comments->comments[n]); free (comments); @@ -142,6 +157,9 @@ _XcursorReadUInt (XcursorFile *file, XcursorUInt *u) { unsigned char bytes[4]; + if (!file || !u) + return XcursorFalse; + if ((*file->read) (file, bytes, 4) != 4) return XcursorFalse; *u = ((bytes[0] << 0) | @@ -154,7 +172,7 @@ _XcursorReadUInt (XcursorFile *file, XcursorUInt *u) static XcursorBool _XcursorReadBytes (XcursorFile *file, char *bytes, int length) { - if ((*file->read) (file, (unsigned char *) bytes, length) != length) + if (!file || !bytes || (*file->read) (file, (unsigned char *) bytes, length) != length) return XcursorFalse; return XcursorTrue; } @@ -164,6 +182,9 @@ _XcursorWriteUInt (XcursorFile *file, XcursorUInt u) { unsigned char bytes[4]; + if (!file) + return XcursorFalse; + bytes[0] = u; bytes[1] = u >> 8; bytes[2] = u >> 16; @@ -176,7 +197,7 @@ _XcursorWriteUInt (XcursorFile *file, XcursorUInt u) static XcursorBool _XcursorWriteBytes (XcursorFile *file, char *bytes, int length) { - if ((*file->write) (file, (unsigned char *) bytes, length) != length) + if (!file || !bytes || (*file->write) (file, (unsigned char *) bytes, length) != length) return XcursorFalse; return XcursorTrue; } @@ -184,7 +205,8 @@ _XcursorWriteBytes (XcursorFile *file, char *bytes, int length) static void _XcursorFileHeaderDestroy (XcursorFileHeader *fileHeader) { - free (fileHeader); + if (!fileHeader) + free (fileHeader); } static XcursorFileHeader * @@ -212,6 +234,9 @@ _XcursorReadFileHeader (XcursorFile *file) XcursorFileHeader head, *fileHeader; XcursorUInt skip; int n; + + if (!file) + return NULL; if (!_XcursorReadUInt (file, &head.magic)) return 0; @@ -262,6 +287,9 @@ static XcursorBool _XcursorWriteFileHeader (XcursorFile *file, XcursorFileHeader *fileHeader) { int toc; + + if (!file || !fileHeader) + return XcursorFalse; if (!_XcursorWriteUInt (file, fileHeader->magic)) return XcursorFalse; @@ -288,7 +316,8 @@ _XcursorSeekToToc (XcursorFile *file, XcursorFileHeader *fileHeader, int toc) { - if ((*file->seek) (file, fileHeader->tocs[toc].position, SEEK_SET) == EOF) + if (!file || !fileHeader || \ + (*file->seek) (file, fileHeader->tocs[toc].position, SEEK_SET) == EOF) return XcursorFalse; return XcursorTrue; } @@ -299,6 +328,8 @@ _XcursorFileReadChunkHeader (XcursorFile *file, int toc, XcursorChunkHeader *chunkHeader) { + if (!file || !fileHeader || !chunkHeader) + return XcursorFalse; if (!_XcursorSeekToToc (file, fileHeader, toc)) return XcursorFalse; if (!_XcursorReadUInt (file, &chunkHeader->header)) @@ -322,6 +353,8 @@ _XcursorFileWriteChunkHeader (XcursorFile *file, int toc, XcursorChunkHeader *chunkHeader) { + if (!file || !fileHeader || !chunkHeader) + return XcursorFalse; if (!_XcursorSeekToToc (file, fileHeader, toc)) return XcursorFalse; if (!_XcursorWriteUInt (file, chunkHeader->header)) @@ -347,6 +380,9 @@ _XcursorFindBestSize (XcursorFileHeader *fileHeader, XcursorDim bestSize = 0; XcursorDim thisSize; + if (!fileHeader || !nsizesp) + return 0; + for (n = 0; n < fileHeader->ntoc; n++) { if (fileHeader->tocs[n].type != XCURSOR_IMAGE_TYPE) @@ -372,6 +408,9 @@ _XcursorFindImageToc (XcursorFileHeader *fileHeader, int toc; XcursorDim thisSize; + if (!fileHeader) + return 0; + for (toc = 0; toc < fileHeader->ntoc; toc++) { if (fileHeader->tocs[toc].type != XCURSOR_IMAGE_TYPE) @@ -399,6 +438,9 @@ _XcursorReadImage (XcursorFile *file, int n; XcursorPixel *p; + if (!file || !fileHeader) + return NULL; + if (!_XcursorFileReadChunkHeader (file, fileHeader, toc, &chunkHeader)) return 0; if (!_XcursorReadUInt (file, &head.width)) @@ -444,6 +486,9 @@ _XcursorReadImage (XcursorFile *file, static XcursorUInt _XcursorImageLength (XcursorImage *image) { + if (!image) + return 0; + return XCURSOR_IMAGE_HEADER_LEN + (image->width * image->height) * 4; } @@ -457,6 +502,9 @@ _XcursorWriteImage (XcursorFile *file, int n; XcursorPixel *p; + if (!file || !fileHeader || !image) + return XcursorFalse; + /* sanity check data */ if (image->width > XCURSOR_IMAGE_MAX_SIZE || image->height > XCURSOR_IMAGE_MAX_SIZE) @@ -508,6 +556,9 @@ _XcursorReadComment (XcursorFile *file, XcursorUInt length; XcursorComment *comment; + if (!file || !fileHeader) + return NULL; + /* read chunk header */ if (!_XcursorFileReadChunkHeader (file, fileHeader, toc, &chunkHeader)) return 0; @@ -541,6 +592,9 @@ _XcursorWriteComment (XcursorFile *file, XcursorChunkHeader chunkHeader; XcursorUInt length; + if (!file || !fileHeader || !comment || !comment->comment) + return XcursorFalse; + length = strlen (comment->comment); /* sanity check data */ @@ -600,7 +654,7 @@ XcursorXcFileLoadImages (XcursorFile *file, int size) int n; int toc; - if (size < 0) + if (!file || size < 0) return 0; fileHeader = _XcursorReadFileHeader (file); if (!fileHeader) @@ -641,6 +695,9 @@ XcursorXcFileLoadAllImages (XcursorFile *file) int n; int toc; + if (!file) + return 0; + fileHeader = _XcursorReadFileHeader (file); if (!fileHeader) return 0; @@ -692,6 +749,8 @@ XcursorXcFileLoad (XcursorFile *file, XcursorComments *comments; int toc; + if (!file) + return 0; fileHeader = _XcursorReadFileHeader (file); if (!fileHeader) return 0; @@ -762,6 +821,9 @@ XcursorXcFileSave (XcursorFile *file, int n; int toc; + if (!file || !comments || !images) + return XcursorFalse; + fileHeader = _XcursorFileHeaderCreate (comments->ncomment + images->nimage); if (!fileHeader) return XcursorFalse; @@ -861,6 +923,9 @@ XcursorFileLoadImage (FILE *file, int size) { XcursorFile f; + if (!file) + return NULL; + _XcursorStdioFileInitialize (file, &f); return XcursorXcFileLoadImage (&f, size); } @@ -870,6 +935,9 @@ XcursorFileLoadImages (FILE *file, int size) { XcursorFile f; + if (!file) + return NULL; + _XcursorStdioFileInitialize (file, &f); return XcursorXcFileLoadImages (&f, size); } @@ -879,6 +947,9 @@ XcursorFileLoadAllImages (FILE *file) { XcursorFile f; + if (!file) + return NULL; + _XcursorStdioFileInitialize (file, &f); return XcursorXcFileLoadAllImages (&f); } @@ -890,6 +961,9 @@ XcursorFileLoad (FILE *file, { XcursorFile f; + if (!file || !commentsp || !imagesp) + return XcursorFalse; + _XcursorStdioFileInitialize (file, &f); return XcursorXcFileLoad (&f, commentsp, imagesp); } @@ -900,7 +974,7 @@ XcursorFileSaveImages (FILE *file, const XcursorImages *images) XcursorComments *comments = XcursorCommentsCreate (0); XcursorFile f; XcursorBool ret; - if (!comments) + if (!comments || !file || !images) return 0; _XcursorStdioFileInitialize (file, &f); ret = XcursorXcFileSave (&f, comments, images) && fflush (file) != EOF; @@ -914,6 +988,9 @@ XcursorFileSave (FILE * file, const XcursorImages *images) { XcursorFile f; + + if (!file || !comments || !images) + return XcursorFalse; _XcursorStdioFileInitialize (file, &f); return XcursorXcFileSave (&f, comments, images) && fflush (file) != EOF; @@ -925,6 +1002,9 @@ XcursorFilenameLoadImage (const char *file, int size) FILE *f; XcursorImage *image; + if (!file || size < 0) + return NULL; + f = fopen (file, "r"); if (!f) return 0; @@ -939,6 +1019,9 @@ XcursorFilenameLoadImages (const char *file, int size) FILE *f; XcursorImages *images; + if (!file || size < 0) + return NULL; + f = fopen (file, "r"); if (!f) return 0; @@ -953,6 +1036,9 @@ XcursorFilenameLoadAllImages (const char *file) FILE *f; XcursorImages *images; + if (!file) + return NULL; + f = fopen (file, "r"); if (!f) return 0; @@ -969,6 +1055,9 @@ XcursorFilenameLoad (const char *file, FILE *f; XcursorBool ret; + if (!file) + return XcursorFalse; + f = fopen (file, "r"); if (!f) return 0; @@ -983,6 +1072,9 @@ XcursorFilenameSaveImages (const char *file, const XcursorImages *images) FILE *f; XcursorBool ret; + if (!file || !images) + return XcursorFalse; + f = fopen (file, "w"); if (!f) return 0; @@ -998,10 +1090,12 @@ XcursorFilenameSave (const char *file, FILE *f; XcursorBool ret; + if (!file || !comments || !images) + return XcursorFalse; + f = fopen (file, "w"); if (!f) return 0; ret = XcursorFileSave (f, comments, images); return fclose (f) != EOF && ret; } - diff --git a/src/library.c b/src/library.c index 90bb6eb..d7d2eaa 100644 --- a/src/library.c +++ b/src/library.c @@ -1,4 +1,5 @@ /* + * $Id$ * * Copyright © 2002 Keith Packard * @@ -80,6 +81,9 @@ _XcursorBuildThemeDir (const char *dir, const char *theme) int themelen; int len; + if (!dir || !theme) + return NULL; + colon = strchr (dir, ':'); if (!colon) colon = dir + strlen (dir); @@ -127,6 +131,9 @@ _XcursorBuildFullname (const char *dir, const char *subdir, const char *file) { char *full; + if (!dir || !subdir || !file) + return NULL; + full = malloc (strlen (dir) + 1 + strlen (subdir) + 1 + strlen (file) + 1); if (!full) return 0; @@ -157,6 +164,9 @@ _XcursorThemeInherits (const char *full) char *result = 0; FILE *f; + if (!full) + return NULL; + f = fopen (full, "r"); if (f) { @@ -207,6 +217,9 @@ XcursorScanTheme (const char *theme, const char *name) char *inherits = 0; const char *i; + if (!theme || !name) + return NULL; + /* * XCURSOR_CORE_THEME is a magic name; cursors from the core set * are never found in any directory. Instead, a magic value is @@ -259,6 +272,9 @@ XcursorLibraryLoadImage (const char *file, const char *theme, int size) FILE *f = 0; XcursorImage *image = 0; + if (!file) + return NULL; + if (theme) f = XcursorScanTheme (theme, file); if (!f) @@ -279,6 +295,9 @@ XcursorLibraryLoadImages (const char *file, const char *theme, int size) FILE *f = 0; XcursorImages *images = 0; + if (!file) + return NULL; + if (theme) f = XcursorScanTheme (theme, file); if (!f) @@ -303,6 +322,9 @@ XcursorLibraryLoadCursor (Display *dpy, const char *file) XcursorImages *images = XcursorLibraryLoadImages (file, theme, size); Cursor cursor; + if (!file) + return 0; + if (!images) { int id = XcursorLibraryShape (file); @@ -328,6 +350,9 @@ XcursorLibraryLoadCursors (Display *dpy, const char *file) XcursorImages *images = XcursorLibraryLoadImages (file, theme, size); XcursorCursors *cursors; + if (!file) + return NULL; + if (!images) { int id = XcursorLibraryShape (file); diff --git a/src/xcursorint.h b/src/xcursorint.h index c697599..1a5f50f 100644 --- a/src/xcursorint.h +++ b/src/xcursorint.h @@ -1,4 +1,5 @@ /* + * $Id$ * * Copyright © 2002 Keith Packard * diff --git a/src/xlib.c b/src/xlib.c index 37c74b9..765cf9d 100644 --- a/src/xlib.c +++ b/src/xlib.c @@ -1,4 +1,5 @@ /* + * $Id$ * * Copyright © 2002 Keith Packard * @@ -36,6 +37,9 @@ _XcursorFontIsCursor (Display *dpy, Font font) int n; Atom cursor; + if (!dpy || !font) + return XcursorFalse; + if (font == dpy->cursor_font) return XcursorTrue; @@ -86,6 +90,9 @@ XcursorTryShapeCursor (Display *dpy, XColor _Xconst *background) { Cursor cursor = None; + + if (!dpy || !source_font || !mask_font || !foreground || !background) + return 0; if (!XcursorSupportsARGB (dpy) && !XcursorGetThemeCore (dpy)) return None; @@ -120,6 +127,9 @@ XcursorNoticeCreateBitmap (Display *dpy, int replace = 0; XcursorBitmapInfo *bmi; + if (!dpy) + return; + if (!XcursorSupportsARGB (dpy) && !XcursorGetThemeCore (dpy)) return; @@ -160,9 +170,14 @@ XcursorNoticeCreateBitmap (Display *dpy, static XcursorBitmapInfo * _XcursorGetBitmap (Display *dpy, Pixmap bitmap) { - XcursorDisplayInfo *info = _XcursorGetDisplayInfo (dpy); + XcursorDisplayInfo *info; int i; + if (!dpy || !bitmap) + return NULL; + + info = _XcursorGetDisplayInfo (dpy); + if (!info) return 0; LockDisplay (dpy); @@ -233,6 +248,9 @@ XcursorImageHash (XImage *image, int low_addr; Bool bit_swap; + if (!image) + return; + for (i = 0; i < XCURSOR_BITMAP_HASH_SIZE; i++) hash[i] = 0; /* @@ -302,6 +320,9 @@ XcursorNoticePutBitmap (Display *dpy, XImage *image) { XcursorBitmapInfo *bmi; + + if (!dpy || !image) + return; if (!XcursorSupportsARGB (dpy) && !XcursorGetThemeCore (dpy)) return; @@ -383,6 +404,9 @@ XcursorTryShapeBitmapCursor (Display *dpy, int i; Cursor cursor; + if (!dpy || !foreground || !background) + return 0; + if (!XcursorSupportsARGB (dpy) && !XcursorGetThemeCore (dpy)) return None; -- cgit v1.2.3