summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2021-03-10 19:36:04 -0500
committerThomas E. Dickey <dickey@invisible-island.net>2021-03-11 20:24:54 -0500
commitcea72e14274d3288b641e14f6cf1171b97485790 (patch)
tree1748ed509df20a4a09bc668ab25dec49e299808a
parent204b6f130858ef038832887ea10488e7aed711a6 (diff)
downloadxorg-lib-libXcursor-cea72e14274d3288b641e14f6cf1171b97485790.tar.gz
quiet normal gcc warnings using casts (no object change)
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
-rw-r--r--src/cursor.c55
-rw-r--r--src/display.c4
-rw-r--r--src/file.c44
-rw-r--r--src/library.c18
-rw-r--r--src/xlib.c2
5 files changed, 64 insertions, 59 deletions
diff --git a/src/cursor.c b/src/cursor.c
index 23c3283..5d6b169 100644
--- a/src/cursor.c
+++ b/src/cursor.c
@@ -30,7 +30,7 @@ XcursorCursorsCreate (Display *dpy, int size)
XcursorCursors *cursors;
cursors = malloc (sizeof (XcursorCursors) +
- size * sizeof (Cursor));
+ (size_t) size * sizeof (Cursor));
if (!cursors)
return NULL;
cursors->ref = 1;
@@ -124,7 +124,7 @@ _XcursorDivideAlpha (XcursorUInt value, XcursorUInt alpha)
value = value * 255 / alpha;
if (value > 255)
value = 255;
- return value | (value << 8);
+ return (unsigned short) (value | (value << 8));
}
static void
@@ -194,6 +194,8 @@ _XcursorCompareBlue (const void *a, const void *b)
return (int) (((*ap >> 0) & 0xff) - ((*bp >> 0) & 0xff));
}
+#define ScaledPixels(c,n) ((c)/(XcursorPixel)(n))
+
static XcursorPixel
_XcursorAverageColor (XcursorPixel *pixels, int npixels)
{
@@ -212,7 +214,10 @@ _XcursorAverageColor (XcursorPixel *pixels, int npixels)
green += (p >> 8) & 0xff;
blue += (p >> 0) & 0xff;
}
- return (0xffU << 24) | ((red/npixels) << 16) | ((green/npixels) << 8) | (blue/npixels);
+ return (0xffU << 24)
+ | (ScaledPixels(red, npixels) << 16)
+ | (ScaledPixels(green, npixels) << 8)
+ | ScaledPixels(blue, npixels);
}
typedef struct XcursorCoreCursor {
@@ -258,7 +263,7 @@ _XcursorHeckbertMedianCut (const XcursorImage *image, XcursorCoreCursor *core)
pc = colors;
max_blue = max_green = max_red = 0;
min_blue = min_green = min_red = 255;
- n = npixels;
+ n = (int) npixels;
while (n--)
{
p = *po++;
@@ -285,7 +290,7 @@ _XcursorHeckbertMedianCut (const XcursorImage *image, XcursorCoreCursor *core)
p = 0;
*pn++ = p;
}
- ncolors = pc - colors;
+ ncolors = (int) (pc - colors);
/*
* Compute longest dimension and sort
@@ -297,7 +302,7 @@ _XcursorHeckbertMedianCut (const XcursorImage *image, XcursorCoreCursor *core)
compare = _XcursorCompareRed;
else
compare = _XcursorCompareBlue;
- qsort (colors, ncolors, sizeof (XcursorPixel), compare);
+ qsort (colors, (size_t) ncolors, sizeof (XcursorPixel), compare);
/*
* Compute average colors on both sides of the cut
*/
@@ -363,8 +368,8 @@ _XcursorBayerOrderedDither (const XcursorImage *image, XcursorCoreCursor *core)
for (x = 0; x < image->width; x++)
{
p = *pixel++;
- a = ((p >> 24) * DITHER_SIZE + 127) / 255;
- i = (_XcursorPixelBrightness (p) * DITHER_SIZE + 127) / 255;
+ a = (XcursorPixel) (((p >> 24) * DITHER_SIZE + 127) / 255);
+ i = (XcursorPixel) ((_XcursorPixelBrightness (p) * DITHER_SIZE + 127) / 255);
d = orderedDither[y&(DITHER_DIM-1)][x&(DITHER_DIM-1)];
if (a > d)
{
@@ -398,9 +403,9 @@ _XcursorFloydSteinberg (const XcursorImage *image, XcursorCoreCursor *core)
unsigned int npixels = image->width * image->height;
int n;
int right = 1;
- int belowLeft = image->width - 1;
- int below = image->width;
- int belowRight = image->width + 1;
+ int belowLeft = (int) (image->width - 1);
+ int below = (int) image->width;
+ int belowRight = (int) (image->width + 1);
int iError, aError;
int iErrorRight, aErrorRight;
int iErrorBelowLeft, aErrorBelowLeft;
@@ -420,7 +425,7 @@ _XcursorFloydSteinberg (const XcursorImage *image, XcursorCoreCursor *core)
pixel = image->pixels;
iP = iPicture;
aP = aPicture;
- n = npixels;
+ n = (int) npixels;
max_inten = 0;
min_inten = 0xff;
while (n--)
@@ -501,10 +506,10 @@ _XcursorFloydSteinberg (const XcursorImage *image, XcursorCoreCursor *core)
free (iPicture);
core->on_color.red =
core->on_color.green =
- core->on_color.blue = (min_inten | min_inten << 8);
+ core->on_color.blue = (unsigned short) (min_inten | min_inten << 8);
core->off_color.red =
core->off_color.green =
- core->off_color.blue = (max_inten | max_inten << 8);
+ core->off_color.blue = (unsigned short) (max_inten | max_inten << 8);
return True;
}
@@ -560,8 +565,8 @@ XcursorImageLoadCursor (Display *dpy, const XcursorImage *image)
GC gc;
XRenderPictFormat *format;
- ximage.width = image->width;
- ximage.height = image->height;
+ ximage.width = (int) image->width;
+ ximage.height = (int) image->height;
ximage.xoffset = 0;
ximage.format = ZPixmap;
ximage.data = (char *) image->pixels;
@@ -571,7 +576,7 @@ XcursorImageLoadCursor (Display *dpy, const XcursorImage *image)
ximage.bitmap_pad = 32;
ximage.depth = 32;
ximage.bits_per_pixel = 32;
- ximage.bytes_per_line = image->width * 4;
+ ximage.bytes_per_line = (int) (image->width * 4);
ximage.red_mask = 0xff0000;
ximage.green_mask = 0x00ff00;
ximage.blue_mask = 0x0000ff;
@@ -608,12 +613,12 @@ XcursorImageLoadCursor (Display *dpy, const XcursorImage *image)
0, NULL, image->width, image->height,
32, 0);
core.src_image->data = Xmalloc (image->height *
- core.src_image->bytes_per_line);
+ (unsigned) core.src_image->bytes_per_line);
core.msk_image = XCreateImage (dpy, NULL, 1, ZPixmap,
0, NULL, image->width, image->height,
32, 0);
core.msk_image->data = Xmalloc (image->height *
- core.msk_image->bytes_per_line);
+ (unsigned) core.msk_image->bytes_per_line);
switch (info->dither) {
case XcursorDitherThreshold:
@@ -708,7 +713,7 @@ XcursorImagesLoadCursor (Display *dpy, const XcursorImages *images)
if (!cursors)
return 0;
- anim = malloc (cursors->ncursor * sizeof (XAnimCursor));
+ anim = malloc ((size_t) cursors->ncursor * sizeof (XAnimCursor));
if (!anim)
{
XcursorCursorsDestroy (cursors);
@@ -777,11 +782,11 @@ _XcursorCreateGlyphCursor(Display *dpy,
LockDisplay(dpy);
GetReq(CreateGlyphCursor, req);
- cid = req->cid = XAllocID(dpy);
- req->source = source_font;
- req->mask = mask_font;
- req->sourceChar = source_char;
- req->maskChar = mask_char;
+ cid = req->cid = (CARD32) XAllocID(dpy);
+ req->source = (CARD32) source_font;
+ req->mask = (CARD32) mask_font;
+ req->sourceChar = (CARD16) source_char;
+ req->maskChar = (CARD16) mask_char;
req->foreRed = foreground->red;
req->foreGreen = foreground->green;
req->foreBlue = foreground->blue;
diff --git a/src/display.c b/src/display.c
index 77dd325..083c3a6 100644
--- a/src/display.c
+++ b/src/display.c
@@ -74,7 +74,7 @@ _XcursorDefaultParseBool (char *v)
c0 = *v;
if (isupper ((int)c0))
- c0 = tolower (c0);
+ c0 = (char) tolower (c0);
if (c0 == 't' || c0 == 'y' || c0 == '1')
return 1;
if (c0 == 'f' || c0 == 'n' || c0 == '0')
@@ -83,7 +83,7 @@ _XcursorDefaultParseBool (char *v)
{
c1 = v[1];
if (isupper ((int)c1))
- c1 = tolower (c1);
+ c1 = (char) tolower (c1);
if (c1 == 'n')
return 1;
if (c1 == 'f')
diff --git a/src/file.c b/src/file.c
index c074f71..c1a5c6a 100644
--- a/src/file.c
+++ b/src/file.c
@@ -35,14 +35,14 @@ XcursorImageCreate (int width, int height)
return NULL;
image = malloc (sizeof (XcursorImage) +
- width * height * sizeof (XcursorPixel));
+ (size_t) (width * height) * sizeof (XcursorPixel));
if (!image)
return NULL;
image->version = XCURSOR_IMAGE_VERSION;
image->pixels = (XcursorPixel *) (image + 1);
- image->size = width > height ? width : height;
- image->width = width;
- image->height = height;
+ image->size = (XcursorDim) (width > height ? width : height);
+ image->width = (XcursorDim) width;
+ image->height = (XcursorDim) height;
image->delay = 0;
return image;
}
@@ -59,7 +59,7 @@ XcursorImagesCreate (int size)
XcursorImages *images;
images = malloc (sizeof (XcursorImages) +
- size * sizeof (XcursorImage *));
+ (size_t) size * sizeof (XcursorImage *));
if (!images)
return NULL;
images->nimage = 0;
@@ -109,7 +109,7 @@ XcursorCommentCreate (XcursorUInt comment_type, int length)
if (length < 0 || length > XCURSOR_COMMENT_MAX_LEN)
return NULL;
- comment = malloc (sizeof (XcursorComment) + length + 1);
+ comment = malloc (sizeof (XcursorComment) + (size_t) length + 1);
if (!comment)
return NULL;
comment->version = XCURSOR_COMMENT_VERSION;
@@ -131,7 +131,7 @@ XcursorCommentsCreate (int size)
XcursorComments *comments;
comments = malloc (sizeof (XcursorComments) +
- size * sizeof (XcursorComment *));
+ (size_t) size * sizeof (XcursorComment *));
if (!comments)
return NULL;
comments->ncomment = 0;
@@ -186,10 +186,10 @@ _XcursorWriteUInt (XcursorFile *file, XcursorUInt u)
if (!file)
return XcursorFalse;
- bytes[0] = u;
- bytes[1] = u >> 8;
- bytes[2] = u >> 16;
- bytes[3] = u >> 24;
+ bytes[0] = (unsigned char)(u);
+ bytes[1] = (unsigned char)(u >> 8);
+ bytes[2] = (unsigned char)(u >> 16);
+ bytes[3] = (unsigned char)(u >> 24);
if ((*file->write) (file, bytes, 4) != 4)
return XcursorFalse;
return XcursorTrue;
@@ -463,7 +463,7 @@ _XcursorReadImage (XcursorFile *file,
return NULL;
/* Create the image and initialize it */
- image = XcursorImageCreate (head.width, head.height);
+ image = XcursorImageCreate ((int) head.width, (int) head.height);
if (image == NULL)
return NULL;
if (chunkHeader.version < image->version)
@@ -472,7 +472,7 @@ _XcursorReadImage (XcursorFile *file,
image->xhot = head.xhot;
image->yhot = head.yhot;
image->delay = head.delay;
- n = image->width * image->height;
+ n = (int) (image->width * image->height);
p = image->pixels;
while (n--)
{
@@ -539,7 +539,7 @@ _XcursorWriteImage (XcursorFile *file,
return XcursorFalse;
/* write the image */
- n = image->width * image->height;
+ n = (int) (image->width * image->height);
p = image->pixels;
while (n--)
{
@@ -568,10 +568,10 @@ _XcursorReadComment (XcursorFile *file,
/* read extra comment header fields */
if (!_XcursorReadUInt (file, &length))
return NULL;
- comment = XcursorCommentCreate (chunkHeader.subtype, length);
+ comment = XcursorCommentCreate (chunkHeader.subtype, (int) length);
if (!comment)
return NULL;
- if (!_XcursorReadBytes (file, comment->comment, length))
+ if (!_XcursorReadBytes (file, comment->comment, (int) length))
{
XcursorCommentDestroy (comment);
return NULL;
@@ -583,7 +583,7 @@ _XcursorReadComment (XcursorFile *file,
static XcursorUInt
_XcursorCommentLength (XcursorComment *comment)
{
- return XCURSOR_COMMENT_HEADER_LEN + strlen (comment->comment);
+ return XCURSOR_COMMENT_HEADER_LEN + (XcursorUInt) strlen (comment->comment);
}
static XcursorBool
@@ -598,7 +598,7 @@ _XcursorWriteComment (XcursorFile *file,
if (!file || !fileHeader || !comment || !comment->comment)
return XcursorFalse;
- length = strlen (comment->comment);
+ length = (XcursorUInt) strlen (comment->comment);
/* sanity check data */
if (length > XCURSOR_COMMENT_MAX_LEN)
@@ -617,7 +617,7 @@ _XcursorWriteComment (XcursorFile *file,
if (!_XcursorWriteUInt (file, length))
return XcursorFalse;
- if (!_XcursorWriteBytes (file, comment->comment, length))
+ if (!_XcursorWriteBytes (file, comment->comment, (int) length))
return XcursorFalse;
return XcursorTrue;
}
@@ -836,7 +836,7 @@ XcursorXcFileSave (XcursorFile *file,
if (!file || !comments || !images)
return XcursorFalse;
- fileHeader = _XcursorFileHeaderCreate (comments->ncomment + images->nimage);
+ fileHeader = _XcursorFileHeaderCreate ((XcursorUInt) (comments->ncomment + images->nimage));
if (!fileHeader)
return XcursorFalse;
@@ -904,14 +904,14 @@ static int
_XcursorStdioFileRead (XcursorFile *file, unsigned char *buf, int len)
{
FILE *f = file->closure;
- return fread (buf, 1, len, f);
+ return (int) fread (buf, 1, (size_t) len, f);
}
static int
_XcursorStdioFileWrite (XcursorFile *file, unsigned char *buf, int len)
{
FILE *f = file->closure;
- return fwrite (buf, 1, len, f);
+ return (int) fwrite (buf, 1, (size_t) len, f);
}
static int
diff --git a/src/library.c b/src/library.c
index 364703d..bf637ea 100644
--- a/src/library.c
+++ b/src/library.c
@@ -58,15 +58,15 @@ _XcursorAddPathElt (char *path, const char *elt, int len)
pathlen++;
}
if (len == -1)
- len = strlen (elt);
+ len = (int) strlen (elt);
/* strip leading slashes */
while (len && elt[0] == '/')
{
elt++;
len--;
}
- strncpy (path + pathlen, elt, len);
- path[pathlen + len] = '\0';
+ strncpy (path + pathlen, elt, (size_t) len);
+ path[pathlen + (size_t) len] = '\0';
}
static char *
@@ -88,13 +88,13 @@ _XcursorBuildThemeDir (const char *dir, const char *theme)
if (!colon)
colon = dir + strlen (dir);
- dirlen = colon - dir;
+ dirlen = (int) (colon - dir);
tcolon = strchr (theme, ':');
if (!tcolon)
tcolon = theme + strlen (theme);
- themelen = tcolon - theme;
+ themelen = (int) (tcolon - theme);
home = NULL;
homelen = 0;
@@ -103,7 +103,7 @@ _XcursorBuildThemeDir (const char *dir, const char *theme)
home = getenv ("HOME");
if (!home)
return NULL;
- homelen = strlen (home);
+ homelen = (int) strlen (home);
dir++;
dirlen--;
}
@@ -114,7 +114,7 @@ _XcursorBuildThemeDir (const char *dir, const char *theme)
*/
len = 1 + homelen + 1 + dirlen + 1 + themelen + 1;
- full = malloc (len);
+ full = malloc ((size_t)len);
if (!full)
return NULL;
full[0] = '\0';
@@ -335,7 +335,7 @@ XcursorLibraryLoadCursor (Display *dpy, const char *file)
int id = XcursorLibraryShape (file);
if (id >= 0)
- return _XcursorCreateFontCursor (dpy, id);
+ return _XcursorCreateFontCursor (dpy, (unsigned) id);
else
return 0;
}
@@ -367,7 +367,7 @@ XcursorLibraryLoadCursors (Display *dpy, const char *file)
cursors = XcursorCursorsCreate (dpy, 1);
if (cursors)
{
- cursors->cursors[0] = _XcursorCreateFontCursor (dpy, id);
+ cursors->cursors[0] = _XcursorCreateFontCursor (dpy, (unsigned) id);
if (cursors->cursors[0] == None)
{
XcursorCursorsDestroy (cursors);
diff --git a/src/xlib.c b/src/xlib.c
index 15716b2..c08abfd 100644
--- a/src/xlib.c
+++ b/src/xlib.c
@@ -291,7 +291,7 @@ XcursorImageHash (XImage *image,
if (bit_swap)
t = _reverse_byte[t];
if (t)
- hash[(i++) & (XCURSOR_BITMAP_HASH_SIZE - 1)] ^= RotByte (t, y & 7);
+ hash[(i++) & (XCURSOR_BITMAP_HASH_SIZE - 1)] ^= (unsigned char) RotByte (t, y & 7);
}
line += image->bytes_per_line;
}