Clang-Tidy fixes (#6725)

(cherry picked from commit 3c501b963d)
This commit is contained in:
Pierre Wendling
2022-12-01 16:07:03 -05:00
committed by Sam Lantinga
parent e29c0661cc
commit d0bbfdbfb8
179 changed files with 1260 additions and 1101 deletions

View File

@@ -705,10 +705,11 @@ static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst,
switch (df->BytesPerPixel) {
case 2:
if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
else
} else {
RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
}
break;
case 4:
RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
@@ -755,8 +756,9 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect,
if (run) {
srcbuf += 2 * run;
ofs += run;
} else if (!ofs)
} else if (ofs == 0) {
goto done;
}
} while (ofs < w);
/* skip padding */
@@ -785,8 +787,9 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect,
if (run) {
srcbuf += 4 * run;
ofs += run;
} else if (!ofs)
} else if (ofs == 0) {
goto done;
}
} while (ofs < w);
} while (--vskip);
}
@@ -850,10 +853,11 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect,
switch (df->BytesPerPixel) {
case 2:
if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
else
} else {
RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
}
break;
case 4:
RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
@@ -1039,15 +1043,17 @@ static int RLEAlphaSurface(SDL_Surface *surface)
if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
copy_opaque = copy_opaque_16;
copy_transl = copy_transl_565;
} else
} else {
return -1;
}
break;
case 0x7fff:
if (df->Gmask == 0x03e0 || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
copy_opaque = copy_opaque_16;
copy_transl = copy_transl_555;
} else
} else {
return -1;
}
break;
default:
return -1;
@@ -1059,8 +1065,9 @@ static int RLEAlphaSurface(SDL_Surface *surface)
maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;
break;
case 4:
if (masksum != 0x00ffffff)
if (masksum != 0x00ffffff) {
return -1; /* requires unused high byte */
}
copy_opaque = copy_32;
copy_transl = copy_32;
max_opaque_run = 255; /* runs stored as short ints */
@@ -1128,11 +1135,13 @@ static int RLEAlphaSurface(SDL_Surface *surface)
do {
int run, skip, len;
skipstart = x;
while (x < w && !ISOPAQUE(src[x], sf))
while (x < w && !ISOPAQUE(src[x], sf)) {
x++;
}
runstart = x;
while (x < w && ISOPAQUE(src[x], sf))
while (x < w && ISOPAQUE(src[x], sf)) {
x++;
}
skip = runstart - skipstart;
if (skip == w) {
blankline = 1;
@@ -1164,11 +1173,13 @@ static int RLEAlphaSurface(SDL_Surface *surface)
do {
int run, skip, len;
skipstart = x;
while (x < w && !ISTRANSL(src[x], sf))
while (x < w && !ISTRANSL(src[x], sf)) {
x++;
}
runstart = x;
while (x < w && ISTRANSL(src[x], sf))
while (x < w && ISTRANSL(src[x], sf)) {
x++;
}
skip = runstart - skipstart;
blankline &= (skip == w);
run = x - runstart;
@@ -1319,16 +1330,19 @@ static int RLEColorkeySurface(SDL_Surface *surface)
int x = 0;
int blankline = 0;
do {
int run, skip, len;
int run, skip;
int len;
int runstart;
int skipstart = x;
/* find run of transparent, then opaque pixels */
while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey) {
x++;
}
runstart = x;
while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey) {
x++;
}
skip = runstart - skipstart;
if (skip == w) {
blankline = 1;
@@ -1342,14 +1356,14 @@ static int RLEColorkeySurface(SDL_Surface *surface)
}
len = SDL_min(run, maxn);
ADD_COUNTS(skip, len);
SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
SDL_memcpy(dst, srcbuf + runstart * bpp, (size_t)len * bpp);
dst += len * bpp;
run -= len;
runstart += len;
while (run) {
len = SDL_min(run, maxn);
ADD_COUNTS(0, len);
SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
SDL_memcpy(dst, srcbuf + runstart * bpp, (size_t)len * bpp);
dst += len * bpp;
runstart += len;
run -= len;
@@ -1477,13 +1491,13 @@ static SDL_bool UnRLEAlpha(SDL_Surface *surface)
uncopy_opaque = uncopy_transl = uncopy_32;
}
surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch);
if (!surface->pixels) {
surface->pixels = SDL_SIMDAlloc((size_t)surface->h * surface->pitch);
if (surface->pixels == NULL) {
return SDL_FALSE;
}
surface->flags |= SDL_SIMD_ALIGNED;
/* fill background with transparent pixels */
SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
SDL_memset(surface->pixels, 0, (size_t)surface->h * surface->pitch);
dst = surface->pixels;
srcbuf = (Uint8 *)(df + 1);
@@ -1543,8 +1557,8 @@ void SDL_UnRLESurface(SDL_Surface *surface, int recode)
SDL_Rect full;
/* re-create the original surface */
surface->pixels = SDL_SIMDAlloc(surface->h * surface->pitch);
if (!surface->pixels) {
surface->pixels = SDL_SIMDAlloc((size_t)surface->h * surface->pitch);
if (surface->pixels == NULL) {
/* Oh crap... */
surface->flags |= SDL_RLEACCEL;
return;

View File

@@ -137,7 +137,7 @@ static SDL_BlitFunc SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int
/* Allow an override for testing .. */
if (override) {
SDL_sscanf(override, "%u", &features);
(void)SDL_sscanf(override, "%u", &features);
} else {
if (SDL_HasMMX()) {
features |= SDL_CPU_MMX;

View File

@@ -1457,18 +1457,22 @@ SDL_CalculateBlitA(SDL_Surface *surface)
if (surface->map->identity) {
if (df->Gmask == 0x7e0) {
#ifdef __MMX__
if (SDL_HasMMX())
if (SDL_HasMMX()) {
return Blit565to565SurfaceAlphaMMX;
else
} else
#endif
{
return Blit565to565SurfaceAlpha;
}
} else if (df->Gmask == 0x3e0) {
#ifdef __MMX__
if (SDL_HasMMX())
if (SDL_HasMMX()) {
return Blit555to555SurfaceAlphaMMX;
else
} else
#endif
{
return Blit555to555SurfaceAlpha;
}
}
}
return BlitNtoNSurfaceAlpha;

View File

@@ -3418,11 +3418,11 @@ SDL_CalculateBlitN(SDL_Surface *surface)
because RLE is the preferred fast way to deal with this.
If a particular case turns out to be useful we'll add it. */
if (srcfmt->BytesPerPixel == 2 && surface->map->identity)
if (srcfmt->BytesPerPixel == 2 && surface->map->identity != 0) {
return Blit2to2Key;
else if (dstfmt->BytesPerPixel == 1)
} else if (dstfmt->BytesPerPixel == 1) {
return BlitNto1Key;
else {
} else {
#if SDL_ALTIVEC_BLITTERS
if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4) && SDL_HasAltiVec()) {
return Blit32to32KeyAltivec;

View File

@@ -616,11 +616,11 @@ done:
return surface;
}
int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
int SDL_SaveBMP_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)
{
Sint64 fp_offset;
int i, pad;
SDL_Surface *surface;
SDL_Surface *intermediate_surface;
Uint8 *bits;
SDL_bool save32bit = SDL_FALSE;
SDL_bool saveLegacyBMP = SDL_FALSE;
@@ -657,35 +657,36 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
Uint32 bV4GammaBlue = 0;
/* Make sure we have somewhere to save */
surface = NULL;
intermediate_surface = NULL;
if (dst) {
#ifdef SAVE_32BIT_BMP
/* We can save alpha information in a 32-bit BMP */
if (saveme->format->BitsPerPixel >= 8 && (saveme->format->Amask ||
saveme->map->info.flags & SDL_COPY_COLORKEY)) {
if (surface->format->BitsPerPixel >= 8 &&
(surface->format->Amask != 0 ||
surface->map->info.flags & SDL_COPY_COLORKEY)) {
save32bit = SDL_TRUE;
}
#endif /* SAVE_32BIT_BMP */
if (saveme->format->palette && !save32bit) {
if (saveme->format->BitsPerPixel == 8) {
surface = saveme;
if (surface->format->palette != NULL && !save32bit) {
if (surface->format->BitsPerPixel == 8) {
intermediate_surface = surface;
} else {
SDL_SetError("%d bpp BMP files not supported",
saveme->format->BitsPerPixel);
surface->format->BitsPerPixel);
}
} else if ((saveme->format->BitsPerPixel == 24) && !save32bit &&
} else if ((surface->format->BitsPerPixel == 24) && !save32bit &&
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
(saveme->format->Rmask == 0x00FF0000) &&
(saveme->format->Gmask == 0x0000FF00) &&
(saveme->format->Bmask == 0x000000FF)
(surface->format->Rmask == 0x00FF0000) &&
(surface->format->Gmask == 0x0000FF00) &&
(surface->format->Bmask == 0x000000FF)
#else
(saveme->format->Rmask == 0x000000FF) &&
(saveme->format->Gmask == 0x0000FF00) &&
(saveme->format->Bmask == 0x00FF0000)
(surface->format->Rmask == 0x000000FF) &&
(surface->format->Gmask == 0x0000FF00) &&
(surface->format->Bmask == 0x00FF0000)
#endif
) {
surface = saveme;
intermediate_surface = surface;
} else {
SDL_PixelFormat format;
@@ -712,8 +713,8 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, SDL_FALSE);
}
if (surface && (SDL_LockSurface(surface) == 0)) {
const int bw = surface->w * surface->format->BytesPerPixel;
if (intermediate_surface && (SDL_LockSurface(intermediate_surface) == 0)) {
const int bw = intermediate_surface->w * intermediate_surface->format->BytesPerPixel;
/* Set the BMP file header values */
bfSize = 0; /* We'll write this when we're done */
@@ -732,16 +733,16 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
/* Set the BMP info values */
biSize = 40;
biWidth = surface->w;
biHeight = surface->h;
biWidth = intermediate_surface->w;
biHeight = intermediate_surface->h;
biPlanes = 1;
biBitCount = surface->format->BitsPerPixel;
biBitCount = intermediate_surface->format->BitsPerPixel;
biCompression = BI_RGB;
biSizeImage = surface->h * surface->pitch;
biSizeImage = intermediate_surface->h * intermediate_surface->pitch;
biXPelsPerMeter = 0;
biYPelsPerMeter = 0;
if (surface->format->palette) {
biClrUsed = surface->format->palette->ncolors;
if (intermediate_surface->format->palette) {
biClrUsed = intermediate_surface->format->palette->ncolors;
} else {
biClrUsed = 0;
}
@@ -791,12 +792,12 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
}
/* Write the palette (in BGR color order) */
if (surface->format->palette) {
if (intermediate_surface->format->palette) {
SDL_Color *colors;
int ncolors;
colors = surface->format->palette->colors;
ncolors = surface->format->palette->ncolors;
colors = intermediate_surface->format->palette->colors;
ncolors = intermediate_surface->format->palette->ncolors;
for (i = 0; i < ncolors; ++i) {
SDL_RWwrite(dst, &colors[i].b, 1, 1);
SDL_RWwrite(dst, &colors[i].g, 1, 1);
@@ -816,10 +817,10 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
}
/* Write the bitmap image upside down */
bits = (Uint8 *)surface->pixels + (surface->h * surface->pitch);
bits = (Uint8 *)intermediate_surface->pixels + (intermediate_surface->h * intermediate_surface->pitch);
pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
while (bits > (Uint8 *)surface->pixels) {
bits -= surface->pitch;
while (bits > (Uint8 *)intermediate_surface->pixels) {
bits -= intermediate_surface->pitch;
if (SDL_RWwrite(dst, bits, 1, bw) != bw) {
SDL_Error(SDL_EFWRITE);
break;
@@ -843,9 +844,9 @@ int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
}
/* Close it up.. */
SDL_UnlockSurface(surface);
if (surface != saveme) {
SDL_FreeSurface(surface);
SDL_UnlockSurface(intermediate_surface);
if (intermediate_surface != surface) {
SDL_FreeSurface(intermediate_surface);
}
}

View File

@@ -162,7 +162,7 @@ int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint
char altErrorText[32];
if (errorText[0] == '\0') {
/* An unknown-to-SDL error code was reported. Report its hexadecimal value, instead of its name. */
SDL_snprintf(altErrorText, SDL_arraysize(altErrorText), "0x%x", (unsigned int)eglErrorCode);
(void)SDL_snprintf(altErrorText, SDL_arraysize(altErrorText), "0x%x", (unsigned int)eglErrorCode);
errorText = altErrorText;
}
return SDL_SetError("%s (call to %s failed, reporting an error of %s)", message, eglFunctionName, errorText);

View File

@@ -333,7 +333,7 @@ int SDL_FillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
if (r->x == 0 && r->y == 0 && r->w == dst->w && r->h == dst->h) {
if (dst->format->BitsPerPixel == 4) {
Uint8 b = (((Uint8)color << 4) | (Uint8)color);
SDL_memset(dst->pixels, b, dst->h * dst->pitch);
SDL_memset(dst->pixels, b, (size_t)dst->h * dst->pitch);
return 1;
}
}

View File

@@ -569,8 +569,9 @@ int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
for (mask = Rmask; !(mask & 0x01); mask >>= 1) {
++format->Rshift;
}
for (; (mask & 0x01); mask >>= 1)
for (; (mask & 0x01); mask >>= 1) {
--format->Rloss;
}
}
format->Gmask = Gmask;
@@ -580,8 +581,9 @@ int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
for (mask = Gmask; !(mask & 0x01); mask >>= 1) {
++format->Gshift;
}
for (; (mask & 0x01); mask >>= 1)
for (; (mask & 0x01); mask >>= 1) {
--format->Gloss;
}
}
format->Bmask = Bmask;
@@ -591,8 +593,9 @@ int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
for (mask = Bmask; !(mask & 0x01); mask >>= 1) {
++format->Bshift;
}
for (; (mask & 0x01); mask >>= 1)
for (; (mask & 0x01); mask >>= 1) {
--format->Bloss;
}
}
format->Amask = Amask;
@@ -602,8 +605,9 @@ int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
for (mask = Amask; !(mask & 0x01); mask >>= 1) {
++format->Ashift;
}
for (; (mask & 0x01); mask >>= 1)
for (; (mask & 0x01); mask >>= 1) {
--format->Aloss;
}
}
format->palette = NULL;

View File

@@ -50,17 +50,17 @@ SDL_CreateShapedWindow(const char *title, unsigned int x, unsigned int y, unsign
SDL_DestroyWindow(result);
return NULL;
}
} else
return NULL;
}
return NULL;
}
SDL_bool
SDL_IsShapedWindow(const SDL_Window *window)
{
if (window == NULL)
if (window == NULL) {
return SDL_FALSE;
else
return (SDL_bool)(window->shaper != NULL);
}
return (SDL_bool)(window->shaper != NULL);
}
/* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */
@@ -71,7 +71,7 @@ void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode, SDL_Surface *shape, Uint
Uint8 r = 0, g = 0, b = 0, alpha = 0;
Uint8 *pixel = NULL;
Uint32 pixel_value = 0, mask_value = 0;
int bytes_per_scanline = (shape->w + (ppb - 1)) / ppb;
size_t bytes_per_scanline = (size_t)(shape->w + (ppb - 1)) / ppb;
Uint8 *bitmap_scanline;
SDL_Color key;
@@ -241,8 +241,9 @@ void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function,
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright, function, closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft, function, closure);
SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright, function, closure);
} else
} else {
function(tree, closure);
}
}
void SDL_FreeShapeTree(SDL_ShapeTree **shape_tree)
@@ -324,17 +325,15 @@ int SDL_GetShapedWindowMode(SDL_Window *window, SDL_WindowShapeMode *shape_mode)
{
if (window != NULL && SDL_IsShapedWindow(window)) {
if (shape_mode == NULL) {
if (SDL_WindowHasAShape(window))
/* The window given has a shape. */
return 0;
else
/* The window given is shapeable but lacks a shape. */
return SDL_WINDOW_LACKS_SHAPE;
if (SDL_WindowHasAShape(window)) {
return 0; /* The window given has a shape. */
} else {
return SDL_WINDOW_LACKS_SHAPE; /* The window given is shapeable but lacks a shape. */
}
} else {
*shape_mode = window->shaper->mode;
return 0;
}
} else
/* The window given is not a valid shapeable window. */
return SDL_NONSHAPEABLE_WINDOW;
}
return SDL_NONSHAPEABLE_WINDOW; /* The window given is not a valid shapeable window. */
}

View File

@@ -304,7 +304,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
window->w, window->h);
if (!data->texture) {
/* codechecker_false_positive [Malloc] Static analyzer doesn't realize allocated `data` is saved to SDL_WINDOWTEXTUREDATA and not leaked here. */
return -1;
return -1; /* NOLINT(clang-analyzer-unix.Malloc) */
}
/* Create framebuffer data */
@@ -313,7 +313,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, U
{
/* Make static analysis happy about potential SDL_malloc(0) calls. */
const size_t allocsize = window->h * data->pitch;
const size_t allocsize = (size_t)window->h * data->pitch;
data->pixels = SDL_malloc((allocsize > 0) ? allocsize : 1);
if (!data->pixels) {
return SDL_OutOfMemory();
@@ -1576,6 +1576,11 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
return NULL;
}
/* Make clang-tidy happy */
if (_this == NULL) {
return NULL;
}
}
/* ensure no more than one of these flags is set */
@@ -3997,7 +4002,7 @@ SDL_GL_CreateContext(SDL_Window *window)
return ctx;
}
int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext ctx)
int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context)
{
int retval;
@@ -4006,12 +4011,12 @@ int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext ctx)
}
if (window == SDL_GL_GetCurrentWindow() &&
ctx == SDL_GL_GetCurrentContext()) {
context == SDL_GL_GetCurrentContext()) {
/* We're already current. */
return 0;
}
if (!ctx) {
if (!context) {
window = NULL;
} else if (window) {
CHECK_WINDOW_MAGIC(window, -1);
@@ -4023,12 +4028,12 @@ int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext ctx)
return SDL_SetError("Use of OpenGL without a window is not supported on this platform");
}
retval = _this->GL_MakeCurrent(_this, window, ctx);
retval = _this->GL_MakeCurrent(_this, window, context);
if (retval == 0) {
_this->current_glwin = window;
_this->current_glctx = ctx;
_this->current_glctx = context;
SDL_TLSSet(_this->current_glwin_tls, window, NULL);
SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
SDL_TLSSet(_this->current_glctx_tls, context, NULL);
}
return retval;
}
@@ -4570,7 +4575,7 @@ SDL_ShouldAllowTopmost(void)
return SDL_GetHintBoolean(SDL_HINT_ALLOW_TOPMOST, SDL_TRUE);
}
int SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *userdata)
int SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *callback_data)
{
CHECK_WINDOW_MAGIC(window, -1);
@@ -4581,7 +4586,7 @@ int SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *userdat
}
window->hit_test = callback;
window->hit_test_data = userdata;
window->hit_test_data = callback_data;
return 0;
}

View File

@@ -231,8 +231,8 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
SDL_SetError(VK_KHR_DISPLAY_EXTENSION_NAME " extension is not enabled in the Vulkan instance.");
goto error;
}
if ((chosenDisplayId = SDL_getenv("SDL_VULKAN_DISPLAY")) != NULL) {
chosenDisplayId = SDL_getenv("SDL_VULKAN_DISPLAY");
if (chosenDisplayId != NULL) {
displayId = SDL_atoi(chosenDisplayId);
}

View File

@@ -465,7 +465,7 @@ int SDL_ConvertPixels_YUV_to_RGB(int width, int height,
void *tmp;
int tmp_pitch = (width * sizeof(Uint32));
tmp = SDL_malloc(tmp_pitch * height);
tmp = SDL_malloc((size_t)tmp_pitch * height);
if (tmp == NULL) {
return SDL_OutOfMemory();
}
@@ -846,7 +846,7 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height,
void *tmp;
int tmp_pitch = (width * sizeof(Uint32));
tmp = SDL_malloc(tmp_pitch * height);
tmp = SDL_malloc((size_t)tmp_pitch * height);
if (tmp == NULL) {
return SDL_OutOfMemory();
}
@@ -995,11 +995,11 @@ static int SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const voi
if (src == dst) {
/* Need to make a copy of the buffer so we don't clobber it while converting */
tmp = (Uint8 *)SDL_malloc(2 * UVheight * srcUVPitch);
tmp = (Uint8 *)SDL_malloc((size_t)2 * UVheight * srcUVPitch);
if (tmp == NULL) {
return SDL_OutOfMemory();
}
SDL_memcpy(tmp, src, 2 * UVheight * srcUVPitch);
SDL_memcpy(tmp, src, (size_t)2 * UVheight * srcUVPitch);
src = tmp;
}
@@ -1068,11 +1068,11 @@ static int SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const vo
if (src == dst) {
/* Need to make a copy of the buffer so we don't clobber it while converting */
tmp = (Uint8 *)SDL_malloc(UVheight * srcUVPitch);
tmp = (Uint8 *)SDL_malloc((size_t)UVheight * srcUVPitch);
if (tmp == NULL) {
return SDL_OutOfMemory();
}
SDL_memcpy(tmp, src, UVheight * srcUVPitch);
SDL_memcpy(tmp, src, (size_t)UVheight * srcUVPitch);
src = tmp;
}

View File

@@ -121,7 +121,7 @@ static SDL_Cursor *Android_CreateEmptyCursor()
if (empty_cursor == NULL) {
SDL_Surface *empty_surface = SDL_CreateRGBSurfaceWithFormat(0, 1, 1, 32, SDL_PIXELFORMAT_ARGB8888);
if (empty_surface) {
SDL_memset(empty_surface->pixels, 0, empty_surface->h * empty_surface->pitch);
SDL_memset(empty_surface->pixels, 0, (size_t)empty_surface->h * empty_surface->pitch);
empty_cursor = Android_CreateCursor(empty_surface, 0, 0);
SDL_FreeSurface(empty_surface);
}

View File

@@ -48,6 +48,7 @@ static SDL_Window *FindSDLWindowForNSWindow(NSWindow *win)
NSWindow *nswindow = ((__bridge SDL_WindowData *) sdlwindow->driverdata).nswindow;
if (win == nswindow)
return sdlwindow;
}
}
}
@@ -192,8 +193,9 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
}
/* Don't do anything if this was not an SDL window that was closed */
if (FindSDLWindowForNSWindow(win) == NULL)
if (FindSDLWindowForNSWindow(win) == NULL) {
return;
}
/* HACK: Make the next window in the z-order key when the key window is
* closed. The custom event loop and/or windowing code we have seems to
@@ -391,7 +393,7 @@ CreateApplicationMenus(void)
[appleMenu addItem:[NSMenuItem separatorItem]];
serviceMenu = [[NSMenu alloc] initWithTitle:@""];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
menuItem = [appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
[menuItem setSubmenu:serviceMenu];
[NSApp setServicesMenu:serviceMenu];

View File

@@ -221,8 +221,9 @@ HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
{
if (modifierFlags & modifiers[i])
SDL_SendKeyboardKey(SDL_PRESSED, code);
else
} else {
SDL_SendKeyboardKey(SDL_RELEASED, code);
}
}
}
}

View File

@@ -81,7 +81,8 @@ SDL_MetalViewEventWatch(void *userdata, SDL_Event *event)
highDPI:(BOOL)highDPI
windowID:(Uint32)windowID;
{
if ((self = [super initWithFrame:frame])) {
self = [super initWithFrame:frame];
if (self != nil) {
self.highDPI = highDPI;
self.sdlWindowID = windowID;
self.wantsLayer = YES;

View File

@@ -64,8 +64,8 @@ int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect
/* Send the data to the display */
if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
char file[128];
SDL_snprintf(file, sizeof(file), "SDL_window%" SDL_PRIu32 "-%8.8d.bmp",
SDL_GetWindowID(window), ++frame_number);
(void)SDL_snprintf(file, sizeof file, "SDL_window%" SDL_PRIu32 "-%8.8d.bmp",
SDL_GetWindowID(window), ++frame_number);
SDL_SaveBMP(surface, file);
}
return 0;

View File

@@ -38,9 +38,6 @@ typedef struct
const char *libname;
} kmsdrmdynlib;
#ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
#define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC NULL
#endif
#ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM
#define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM NULL
#endif

View File

@@ -171,7 +171,7 @@ static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor)
/* Copy from the cursor buffer to a buffer that we can dump to the GBM BO. */
for (i = 0; i < curdata->h; i++) {
src_row = &((uint8_t *)curdata->buffer)[i * curdata->w * 4];
SDL_memcpy(ready_buffer + (i * bo_stride), src_row, 4 * curdata->w);
SDL_memcpy(ready_buffer + (i * bo_stride), src_row, (size_t)4 * curdata->w);
}
/* Dump the cursor buffer to our GBM BO. */
@@ -261,7 +261,7 @@ static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_
/* Configure the cursor buffer info.
This buffer has the original size of the cursor surface we are given. */
curdata->buffer_pitch = surface->w;
curdata->buffer_size = surface->w * surface->h * 4;
curdata->buffer_size = (size_t)surface->w * surface->h * 4;
curdata->buffer = (uint32_t *)SDL_malloc(curdata->buffer_size);
if (!curdata->buffer) {

View File

@@ -197,8 +197,8 @@ static int KMSDRM_Available(void)
kmsdrm_dri_pathsize = SDL_strlen(kmsdrm_dri_path);
kmsdrm_dri_devnamesize = SDL_strlen(kmsdrm_dri_devname);
SDL_snprintf(kmsdrm_dri_cardpath, sizeof(kmsdrm_dri_cardpath), "%s%s",
kmsdrm_dri_path, kmsdrm_dri_devname);
(void)SDL_snprintf(kmsdrm_dri_cardpath, sizeof kmsdrm_dri_cardpath, "%s%s",
kmsdrm_dri_path, kmsdrm_dri_devname);
ret = get_driindex();
if (ret >= 0) {
@@ -878,7 +878,7 @@ cleanup:
SDL_free(dispdata);
}
}
}
} /* NOLINT(clang-analyzer-unix.Malloc): If no error `dispdata` is saved in the display */
/* Initializes the list of SDL displays: we build a new display for each
connecter connector we find.
@@ -897,8 +897,8 @@ static int KMSDRM_InitDisplays(_THIS)
int i;
/* Open /dev/dri/cardNN (/dev/drmN if on OpenBSD version less than 6.9) */
SDL_snprintf(viddata->devpath, sizeof(viddata->devpath), "%s%d",
kmsdrm_dri_cardpath, viddata->devindex);
(void)SDL_snprintf(viddata->devpath, sizeof viddata->devpath, "%s%d",
kmsdrm_dri_cardpath, viddata->devindex);
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Opening device %s", viddata->devpath);
viddata->drm_fd = open(viddata->devpath, O_RDWR | O_CLOEXEC);
@@ -1441,7 +1441,8 @@ int KMSDRM_CreateWindow(_THIS, SDL_Window *window)
/* Reopen FD, create gbm dev, setup display plane, etc,.
but only when we come here for the first time,
and only if it's not a VK window. */
if ((ret = KMSDRM_GBMInit(_this, dispdata))) {
ret = KMSDRM_GBMInit(_this, dispdata);
if (ret != 0) {
return SDL_SetError("Can't init GBM on window creation.");
}
}
@@ -1490,7 +1491,8 @@ int KMSDRM_CreateWindow(_THIS, SDL_Window *window)
/* Create the window surfaces with the size we have just chosen.
Needs the window diverdata in place. */
if ((ret = KMSDRM_CreateSurfaces(_this, window))) {
ret = KMSDRM_CreateSurfaces(_this, window);
if (ret == 0) {
return SDL_SetError("Can't window GBM/EGL surfaces on window creation.");
}
} /* NON-Vulkan block ends. */

View File

@@ -64,8 +64,8 @@ int SDL_OFFSCREEN_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_R
/* Send the data to the display */
if (SDL_getenv("SDL_VIDEO_OFFSCREEN_SAVE_FRAMES")) {
char file[128];
SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
(int)SDL_GetWindowID(window), ++frame_number);
(void)SDL_snprintf(file, sizeof file, "SDL_window%" SDL_PRIu32 "-%8.8d.bmp",
SDL_GetWindowID(window), ++frame_number);
SDL_SaveBMP(surface, file);
}
return 0;

View File

@@ -256,9 +256,11 @@ Wayland_source_send(SDL_MimeDataList *mime_data, const char *mime_type, int fd)
status = SDL_SetError("Invalid mime type");
close(fd);
} else {
while (write_pipe(fd, mime_data->data, mime_data->length,
&written_bytes) > 0)
;
while (write_pipe(fd,
mime_data->data,
mime_data->length,
&written_bytes) > 0) {
}
close(fd);
status = written_bytes;
}
@@ -422,10 +424,9 @@ void Wayland_primary_selection_source_destroy(SDL_WaylandPrimarySelectionSource
}
}
void *
Wayland_data_offer_receive(SDL_WaylandDataOffer *offer,
size_t *length, const char *mime_type,
SDL_bool null_terminate)
void *Wayland_data_offer_receive(SDL_WaylandDataOffer *offer,
size_t *length, const char *mime_type,
SDL_bool null_terminate)
{
SDL_WaylandDataDevice *data_device = NULL;
@@ -435,7 +436,10 @@ Wayland_data_offer_receive(SDL_WaylandDataOffer *offer,
if (offer == NULL) {
SDL_SetError("Invalid data offer");
} else if ((data_device = offer->data_device) == NULL) {
return NULL;
}
data_device = offer->data_device;
if (data_device == NULL) {
SDL_SetError("Data device not initialized");
} else if (pipe2(pipefd, O_CLOEXEC | O_NONBLOCK) == -1) {
SDL_SetError("Could not read pipe");
@@ -447,8 +451,8 @@ Wayland_data_offer_receive(SDL_WaylandDataOffer *offer,
close(pipefd[1]);
while (read_pipe(pipefd[0], &buffer, length, null_terminate) > 0)
;
while (read_pipe(pipefd[0], &buffer, length, null_terminate) > 0) {
}
close(pipefd[0]);
}
return buffer;
@@ -467,7 +471,10 @@ Wayland_primary_selection_offer_receive(SDL_WaylandPrimarySelectionOffer *offer,
if (offer == NULL) {
SDL_SetError("Invalid data offer");
} else if ((primary_selection_device = offer->primary_selection_device) == NULL) {
return NULL;
}
primary_selection_device = offer->primary_selection_device;
if (primary_selection_device == NULL) {
SDL_SetError("Primary selection device not initialized");
} else if (pipe2(pipefd, O_CLOEXEC | O_NONBLOCK) == -1) {
SDL_SetError("Could not read pipe");
@@ -479,8 +486,8 @@ Wayland_primary_selection_offer_receive(SDL_WaylandPrimarySelectionOffer *offer,
close(pipefd[1]);
while (read_pipe(pipefd[0], &buffer, length, null_terminate) > 0)
;
while (read_pipe(pipefd[0], &buffer, length, null_terminate) > 0) {
}
close(pipefd[0]);
}
return buffer;

View File

@@ -723,10 +723,11 @@ static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
{
struct SDL_WaylandInput *input = data;
if (wl_seat_get_version(input->seat) >= 5)
if (wl_seat_get_version(input->seat) >= 5) {
pointer_handle_axis_common(input, AXIS_EVENT_CONTINUOUS, axis, value);
else
} else {
pointer_handle_axis_common_v1(input, time, axis, value);
}
}
static void pointer_handle_frame(void *data, struct wl_pointer *pointer)
@@ -1007,9 +1008,12 @@ static void keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
*/
/* Look up the preferred locale, falling back to "C" as default */
if (!(locale = SDL_getenv("LC_ALL"))) {
if (!(locale = SDL_getenv("LC_CTYPE"))) {
if (!(locale = SDL_getenv("LANG"))) {
locale = SDL_getenv("LC_ALL");
if (locale == NULL) {
locale = SDL_getenv("LC_CTYPE");
if (locale == NULL) {
locale = SDL_getenv("LANG");
if (locale == NULL) {
locale = "C";
}
}

View File

@@ -152,7 +152,7 @@ int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *button
return SDL_SetError("Couldn't open pipe for reading: %s", strerror(errno));
}
tmp = fgets(output, output_len + 1, outputfp);
fclose(outputfp);
(void)fclose(outputfp);
if ((tmp == NULL) || (*tmp == '\0') || (*tmp == '\n')) {
SDL_free(output);

View File

@@ -107,10 +107,9 @@ static char *get_classname()
/* Next look at the application's executable name */
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
(void)SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
#elif defined(__FREEBSD__)
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file",
getpid());
(void)SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid());
#else
#error Where can we find the executable name?
#endif
@@ -695,10 +694,10 @@ static void Wayland_add_display(SDL_VideoData *d, uint32_t id)
/* Keep a list of outputs for deferred xdg-output initialization. */
if (d->output_list != NULL) {
SDL_WaylandOutputData *node = (SDL_WaylandOutputData *)d->output_list;
SDL_WaylandOutputData *node = d->output_list;
while (node->next != NULL) {
node = (SDL_WaylandOutputData *)node->next;
node = node->next;
}
node->next = (struct SDL_WaylandOutputData *)data;

View File

@@ -882,8 +882,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
data->last_raw_mouse_position.x = x;
data->last_raw_mouse_position.y = y;
}
relX = (int)(x - data->last_raw_mouse_position.x);
relY = (int)(y - data->last_raw_mouse_position.y);
relX = x - data->last_raw_mouse_position.x;
relY = y - data->last_raw_mouse_position.y;
if (remote_desktop) {
if (!data->in_title_click && !data->focus_click_pending) {
@@ -938,10 +938,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
short amount = GET_WHEEL_DELTA_WPARAM(wParam);
float fAmount = (float)amount / WHEEL_DELTA;
if (msg == WM_MOUSEWHEEL)
if (msg == WM_MOUSEWHEEL) {
SDL_SendMouseWheel(data->window, 0, 0.0f, fAmount, SDL_MOUSEWHEEL_NORMAL);
else
} else {
SDL_SendMouseWheel(data->window, 0, fAmount, 0.0f, SDL_MOUSEWHEEL_NORMAL);
}
} break;
case WM_MOUSELEAVE:
@@ -1172,11 +1173,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
info->ptMaxPosition.x = SDL_min(0, ((screenW - w) / 2));
info->ptMaxPosition.y = SDL_min(0, ((screenH - h) / 2));
}
info->ptMinTrackSize.x = w + min_w;
info->ptMinTrackSize.y = h + min_h;
info->ptMinTrackSize.x = (LONG)w + min_w;
info->ptMinTrackSize.y = (LONG)h + min_h;
if (constrain_max_size) {
info->ptMaxTrackSize.x = w + max_w;
info->ptMaxTrackSize.y = h + max_h;
info->ptMaxTrackSize.x = (LONG)w + max_w;
info->ptMaxTrackSize.y = (LONG)h + max_h;
}
} else {
info->ptMaxSize.x = w;

View File

@@ -81,7 +81,7 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
info->bmiHeader.biWidth = window->w;
info->bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */
info->bmiHeader.biSizeImage = window->h * (*pitch);
info->bmiHeader.biSizeImage = (DWORD)window->h * (*pitch);
data->mdc = CreateCompatibleDC(data->hdc);
data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0);

View File

@@ -36,7 +36,6 @@ static void IME_Init(SDL_VideoData *videodata, HWND hwnd);
static void IME_Enable(SDL_VideoData *videodata, HWND hwnd);
static void IME_Disable(SDL_VideoData *videodata, HWND hwnd);
static void IME_Quit(SDL_VideoData *videodata);
static void IME_ClearComposition(SDL_VideoData *videodata);
static SDL_bool IME_IsTextInputShown(SDL_VideoData *videodata);
#endif /* !SDL_DISABLE_WINDOWS_IME */
@@ -259,9 +258,9 @@ void WIN_SetTextInputRect(_THIS, const SDL_Rect *rect)
cof.ptCurrentPos.x = videodata->ime_rect.x;
cof.ptCurrentPos.y = videodata->ime_rect.y;
cof.rcArea.left = videodata->ime_rect.x;
cof.rcArea.right = videodata->ime_rect.x + videodata->ime_rect.w;
cof.rcArea.right = (LONG)videodata->ime_rect.x + videodata->ime_rect.w;
cof.rcArea.top = videodata->ime_rect.y;
cof.rcArea.bottom = videodata->ime_rect.y + videodata->ime_rect.h;
cof.rcArea.bottom = (LONG)videodata->ime_rect.y + videodata->ime_rect.h;
ImmSetCompositionWindow(himc, &cof);
caf.dwIndex = 0;
@@ -269,9 +268,9 @@ void WIN_SetTextInputRect(_THIS, const SDL_Rect *rect)
caf.ptCurrentPos.x = videodata->ime_rect.x;
caf.ptCurrentPos.y = videodata->ime_rect.y;
caf.rcArea.left = videodata->ime_rect.x;
caf.rcArea.right = videodata->ime_rect.x + videodata->ime_rect.w;
caf.rcArea.right = (LONG)videodata->ime_rect.x + videodata->ime_rect.w;
caf.rcArea.top = videodata->ime_rect.y;
caf.rcArea.bottom = videodata->ime_rect.y + videodata->ime_rect.h;
caf.rcArea.bottom = (LONG)videodata->ime_rect.y + videodata->ime_rect.h;
ImmSetCandidateWindow(himc, &caf);
ImmReleaseContext(videodata->ime_hwnd_current, himc);
@@ -380,8 +379,9 @@ static void IME_Init(SDL_VideoData *videodata, HWND hwnd)
{
HRESULT hResult = S_OK;
if (videodata->ime_initialized)
if (videodata->ime_initialized) {
return;
}
videodata->ime_hwnd_main = hwnd;
if (SUCCEEDED(WIN_CoInitialize())) {
@@ -418,10 +418,11 @@ static void IME_Init(SDL_VideoData *videodata, HWND hwnd)
videodata->ime_available = SDL_TRUE;
IME_UpdateInputLocale(videodata);
IME_SetupAPI(videodata);
if (WIN_ShouldShowNativeUI())
if (WIN_ShouldShowNativeUI()) {
videodata->ime_uiless = SDL_FALSE;
else
} else {
videodata->ime_uiless = UILess_SetupSinks(videodata);
}
IME_UpdateInputLocale(videodata);
IME_Disable(videodata, hwnd);
}
@@ -550,7 +551,7 @@ static void IME_GetReadingString(SDL_VideoData *videodata, HWND hwnd)
break;
}
p = *(LPBYTE *)((LPBYTE)p + 1 * 4 + 5 * 4);
p = *(LPBYTE *)(p + 1 * 4 + 5 * 4);
if (!p) {
break;
}
@@ -1014,8 +1015,9 @@ IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoD
if (wParam == VK_PROCESSKEY) {
videodata->ime_uicontext = 1;
trap = SDL_TRUE;
} else
} else {
videodata->ime_uicontext = 0;
}
break;
case WM_INPUTLANGCHANGE:
IME_InputLangChanged(videodata);
@@ -1149,10 +1151,11 @@ static void UILess_GetCandidateList(SDL_VideoData *videodata, ITfCandidateListUI
if (idxlist) {
pcandlist->lpVtbl->GetPageIndex(pcandlist, idxlist, pgcount, &pgcount);
pgstart = idxlist[page];
if (page < pgcount - 1)
if (page < pgcount - 1) {
pgsize = SDL_min(count, idxlist[page + 1]) - pgstart;
else
} else {
pgsize = count - pgstart;
}
SDL_free(idxlist);
}
@@ -1444,7 +1447,7 @@ static void *StartDrawToBitmap(HDC hdc, HBITMAP *hhbm, int width, int height)
SDL_zero(info);
infoHeader->biSize = sizeof(BITMAPINFOHEADER);
infoHeader->biWidth = width;
infoHeader->biHeight = -1 * SDL_abs(height);
infoHeader->biHeight = (LONG)-1 * SDL_abs(height);
infoHeader->biPlanes = 1;
infoHeader->biBitCount = 32;
infoHeader->biCompression = BI_RGB;
@@ -1623,7 +1626,7 @@ static void IME_RenderCandidateList(SDL_VideoData *videodata, HDC hdc)
(candcount * maxcandsize.cy);
} else {
size.cx =
(listborder * 2) +
(LONG)(listborder * 2) +
(listpadding * 2) +
((candcount + 1) * candmargin) +
(candcount * candborder * 2) +

View File

@@ -804,13 +804,13 @@ static int WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int *
}
/* Ensure the size is wide enough for all of the buttons. */
if (Size.cx < messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin) {
Size.cx = messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin;
if (Size.cx < (LONG)messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin) {
Size.cx = (LONG)messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin;
}
/* Reset the height to the icon size if it is actually bigger than the text. */
if (icon && Size.cy < IconMargin * 2 + IconHeight) {
Size.cy = IconMargin * 2 + IconHeight;
if (icon && Size.cy < (LONG)IconMargin * 2 + IconHeight) {
Size.cy = (LONG)IconMargin * 2 + IconHeight;
}
/* Add vertical space for the buttons and border. */

View File

@@ -42,6 +42,7 @@ static void WIN_UpdateDisplayMode(_THIS, LPCWSTR deviceName, DWORD index, SDL_Di
(DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
DM_DISPLAYFLAGS);
/* NOLINTNEXTLINE(bugprone-assignment-in-if-condition): No simple way to extract the assignment */
if (index == ENUM_CURRENT_SETTINGS && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
LPBITMAPINFO bmi;

View File

@@ -134,7 +134,7 @@ static SDL_Cursor *WIN_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
SDL_assert(surface->pitch == surface->w * 4);
SDL_memcpy(pixels, surface->pixels, surface->h * surface->pitch);
SDL_memcpy(pixels, surface->pixels, (size_t)surface->h * surface->pitch);
hicon = CreateIconIndirect(&ii);
@@ -391,7 +391,7 @@ void WIN_QuitMouse(_THIS)
* https://superuser.com/questions/278362/windows-mouse-acceleration-curve-smoothmousexcurve-and-smoothmouseycurve
* http://www.esreality.com/?a=post&id=1846538/
*/
static SDL_bool LoadFiveFixedPointFloats(BYTE *bytes, float *values)
static SDL_bool LoadFiveFixedPointFloats(const BYTE *bytes, float *values)
{
int i;

View File

@@ -67,8 +67,9 @@ static void CombineRectRegions(SDL_ShapeTree *node, void *closure)
if (mask_region != NULL) {
CombineRgn(mask_region, mask_region, temp_region, RGN_OR);
DeleteObject(temp_region);
} else
} else {
*((HRGN *)closure) = temp_region;
}
}
}

View File

@@ -137,7 +137,7 @@ SDL_bool WIN_Vulkan_CreateSurface(_THIS,
(PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR =
(PFN_vkCreateWin32SurfaceKHR)vkGetInstanceProcAddr(
(VkInstance)instance,
instance,
"vkCreateWin32SurfaceKHR");
VkWin32SurfaceCreateInfoKHR createInfo;
VkResult result;

View File

@@ -174,17 +174,19 @@ static void WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL
screen_rect.left = *x;
screen_rect.top = *y;
screen_rect.right = *x + *width;
screen_rect.bottom = *y + *height;
screen_rect.right = (LONG)*x + *width;
screen_rect.bottom = (LONG)*y + *height;
mon = MonitorFromRect(&screen_rect, MONITOR_DEFAULTTONEAREST);
/* GetDpiForMonitor docs promise to return the same hdpi / vdpi */
if (videodata->GetDpiForMonitor(mon, MDT_EFFECTIVE_DPI, &frame_dpi, &unused) != S_OK) {
frame_dpi = 96;
}
if (videodata != NULL) {
/* GetDpiForMonitor docs promise to return the same hdpi / vdpi */
if (videodata->GetDpiForMonitor(mon, MDT_EFFECTIVE_DPI, &frame_dpi, &unused) != S_OK) {
frame_dpi = 96;
}
videodata->AdjustWindowRectExForDpi(&rect, style, menu, 0, frame_dpi);
videodata->AdjustWindowRectExForDpi(&rect, style, menu, 0, frame_dpi);
}
} else {
AdjustWindowRectEx(&rect, style, menu, 0);
}
@@ -600,7 +602,7 @@ int WIN_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
the window to share a pixel format with
*/
SDL_Window *otherWindow = NULL;
SDL_sscanf(hint, "%p", (void **)&otherWindow);
(void)SDL_sscanf(hint, "%p", (void **)&otherWindow);
/* Do some error checking on the pointer */
if (otherWindow != NULL && otherWindow->magic == &_this->window_magic) {
@@ -1373,7 +1375,7 @@ int WIN_SetWindowOpacity(_THIS, SDL_Window *window, float opacity)
return -1;
#else
const SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
const HWND hwnd = data->hwnd;
HWND hwnd = data->hwnd;
const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
SDL_assert(style != 0);

View File

@@ -106,8 +106,8 @@ extern SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window * window,
extern void WIN_OnWindowEnter(_THIS, SDL_Window * window);
extern void WIN_UpdateClipCursor(SDL_Window *window);
extern int WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
extern void WIN_ClientPointToSDL(const SDL_Window *window, int *w, int *h);
extern void WIN_ClientPointFromSDL(const SDL_Window *window, int *w, int *h);
extern void WIN_ClientPointToSDL(const SDL_Window *window, int *x, int *y);
extern void WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y);
extern void WIN_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept);
extern int WIN_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation);

View File

@@ -521,8 +521,8 @@ static void InitiateWindowMove(_THIS, const SDL_WindowData *data, const SDL_Poin
evt.xclient.window = data->xwindow;
evt.xclient.message_type = X11_XInternAtom(display, "_NET_WM_MOVERESIZE", True);
evt.xclient.format = 32;
evt.xclient.data.l[0] = window->x + point->x;
evt.xclient.data.l[1] = window->y + point->y;
evt.xclient.data.l[0] = (size_t)window->x + point->x;
evt.xclient.data.l[1] = (size_t)window->y + point->y;
evt.xclient.data.l[2] = _NET_WM_MOVERESIZE_MOVE;
evt.xclient.data.l[3] = Button1;
evt.xclient.data.l[4] = 0;
@@ -550,8 +550,8 @@ static void InitiateWindowResize(_THIS, const SDL_WindowData *data, const SDL_Po
evt.xclient.window = data->xwindow;
evt.xclient.message_type = X11_XInternAtom(display, "_NET_WM_MOVERESIZE", True);
evt.xclient.format = 32;
evt.xclient.data.l[0] = window->x + point->x;
evt.xclient.data.l[1] = window->y + point->y;
evt.xclient.data.l[0] = (size_t)window->x + point->x;
evt.xclient.data.l[1] = (size_t)window->y + point->y;
evt.xclient.data.l[2] = direction;
evt.xclient.data.l[3] = Button1;
evt.xclient.data.l[4] = 0;

View File

@@ -30,13 +30,14 @@
/* Shared memory error handler routine */
static int shm_error;
static int (*X_handler)(Display *, XErrorEvent *) = NULL;
static int shm_errhandler(Display *d, XErrorEvent *e)
static int
shm_errhandler(Display *d, XErrorEvent *e)
{
if (e->error_code == BadAccess) {
shm_error = True;
return 0;
} else
return X_handler(d, e);
}
return X_handler(d, e);
}
static SDL_bool have_mitshm(Display *dpy)
@@ -83,7 +84,7 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
if (have_mitshm(display)) {
XShmSegmentInfo *shminfo = &data->shminfo;
shminfo->shmid = shmget(IPC_PRIVATE, window->h * (*pitch), IPC_CREAT | 0777);
shminfo->shmid = shmget(IPC_PRIVATE, (size_t)window->h * (*pitch), IPC_CREAT | 0777);
if (shminfo->shmid >= 0) {
shminfo->shmaddr = (char *)shmat(shminfo->shmid, 0, 0);
shminfo->readOnly = False;
@@ -123,7 +124,7 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format,
}
#endif /* not NO_SHARED_MEMORY */
*pixels = SDL_malloc(window->h * (*pitch));
*pixels = SDL_malloc((size_t)window->h * (*pitch));
if (*pixels == NULL) {
return SDL_OutOfMemory();
}

View File

@@ -85,7 +85,8 @@ X11_KeyCodeToSym(_THIS, KeyCode keycode, unsigned char group)
int action = XkbOutOfRangeGroupAction(info);
if (action == XkbRedirectIntoRange) {
if ((group = XkbOutOfRangeGroupNumber(info)) >= num_groups) {
group = XkbOutOfRangeGroupNumber(info);
if (group >= num_groups) {
group = 0;
}
} else if (action == XkbClampIntoRange) {
@@ -176,14 +177,14 @@ int X11_InitKeyboard(_THIS)
new_xmods = "@im=none";
}
setlocale(LC_ALL, "");
(void)setlocale(LC_ALL, "");
X11_XSetLocaleModifiers(new_xmods);
data->im = X11_XOpenIM(data->display, NULL, data->classname, data->classname);
/* Reset the locale + X locale modifiers back to how they were,
locale first because the X locale modifiers depend on it. */
setlocale(LC_ALL, prev_locale);
(void)setlocale(LC_ALL, prev_locale);
X11_XSetLocaleModifiers(prev_xmods);
if (prev_locale) {
@@ -451,9 +452,9 @@ void X11_ShowScreenKeyboard(_THIS, SDL_Window *window)
* https://partner.steamgames.com/doc/api/ISteamUtils#ShowFloatingGamepadTextInput
*/
char deeplink[128];
SDL_snprintf(deeplink, sizeof(deeplink),
"steam://open/keyboard?XPosition=0&YPosition=0&Width=0&Height=0&Mode=%d",
SDL_GetHintBoolean(SDL_HINT_RETURN_KEY_HIDES_IME, SDL_FALSE) ? 0 : 1);
(void)SDL_snprintf(deeplink, sizeof deeplink,
"steam://open/keyboard?XPosition=0&YPosition=0&Width=0&Height=0&Mode=%d",
SDL_GetHintBoolean(SDL_HINT_RETURN_KEY_HIDES_IME, SDL_FALSE) ? 0 : 1);
SDL_OpenURL(deeplink);
videodata->steam_keyboard_open = SDL_TRUE;
}

View File

@@ -240,7 +240,7 @@ static int X11_MessageBoxInitPositions(SDL_MessageBoxDataX11 *data)
const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
/* Go over text and break linefeeds into separate lines. */
if (messageboxdata->message[0]) {
if (messageboxdata != NULL && messageboxdata->message[0]) {
const char *text = messageboxdata->message;
const int linecount = CountLinesOfText(text);
TextLineData *plinedata = (TextLineData *)SDL_malloc(sizeof(TextLineData) * linecount);
@@ -588,6 +588,7 @@ static void X11_MessageBoxDraw(SDL_MessageBoxDataX11 *data, GC ctx)
#endif
}
/* NOLINTNEXTLINE(readability-non-const-parameter): cannot make XPointer a const pointer due to typedef */
static Bool X11_MessageBoxEventTest(Display *display, XEvent *event, XPointer arg)
{
const SDL_MessageBoxDataX11 *data = (const SDL_MessageBoxDataX11 *)arg;
@@ -766,7 +767,7 @@ static int X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int
if (origlocale == NULL) {
return SDL_OutOfMemory();
}
setlocale(LC_ALL, "");
(void)setlocale(LC_ALL, "");
}
#endif
@@ -792,7 +793,7 @@ static int X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int
#if SDL_SET_LOCALE
if (origlocale) {
setlocale(LC_ALL, origlocale);
(void)setlocale(LC_ALL, origlocale);
SDL_free(origlocale);
}
#endif

View File

@@ -274,7 +274,7 @@ static void SetXRandRDisplayName(Display *dpy, Atom EDID, char *name, const size
inches = (int)((SDL_sqrtf(widthmm * widthmm + heightmm * heightmm) / 25.4f) + 0.5f);
if (*name && inches) {
const size_t len = SDL_strlen(name);
SDL_snprintf(&name[len], namelen - len, " %d\"", inches);
(void)SDL_snprintf(&name[len], namelen - len, " %d\"", inches);
}
#ifdef X11MODES_DEBUG

View File

@@ -98,7 +98,7 @@ static Cursor X11_CreateXCursorCursor(SDL_Surface *surface, int hot_x, int hot_y
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
SDL_assert(surface->pitch == surface->w * 4);
SDL_memcpy(image->pixels, surface->pixels, surface->h * surface->pitch);
SDL_memcpy(image->pixels, surface->pixels, (size_t)surface->h * surface->pitch);
cursor = X11_XcursorImageLoadCursor(display, image);
@@ -118,7 +118,7 @@ static Cursor X11_CreatePixmapCursor(SDL_Surface *surface, int hot_x, int hot_y)
Pixmap data_pixmap, mask_pixmap;
int x, y;
unsigned int rfg, gfg, bfg, rbg, gbg, bbg, fgBits, bgBits;
unsigned int width_bytes = ((surface->w + 7) & ~7) / 8;
size_t width_bytes = ((surface->w + 7) & ~((size_t)7)) / 8;
data_bits = SDL_calloc(1, surface->h * width_bytes);
if (data_bits == NULL) {
@@ -168,15 +168,17 @@ static Cursor X11_CreatePixmapCursor(SDL_Surface *surface, int hot_x, int hot_y)
fg.red = rfg * 257 / fgBits;
fg.green = gfg * 257 / fgBits;
fg.blue = bfg * 257 / fgBits;
} else
} else {
fg.red = fg.green = fg.blue = 0;
}
if (bgBits) {
bg.red = rbg * 257 / bgBits;
bg.green = gbg * 257 / bgBits;
bg.blue = bbg * 257 / bgBits;
} else
} else {
bg.red = bg.green = bg.blue = 0;
}
data_pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
(char *)data_bits,

View File

@@ -35,6 +35,6 @@ typedef struct
extern SDL_WindowShaper *X11_CreateShaper(SDL_Window *window);
extern int X11_ResizeWindowShape(SDL_Window *window);
extern int X11_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shapeMode);
extern int X11_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode);
#endif /* SDL_x11shape_h_ */

View File

@@ -67,10 +67,9 @@ static char *get_classname()
/* Next look at the application's executable name */
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
(void)SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
#elif defined(__FREEBSD__)
SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file",
getpid());
(void)SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid());
#else
#error Where can we find the executable name?
#endif

View File

@@ -45,11 +45,13 @@
#define _NET_WM_STATE_REMOVE 0l
#define _NET_WM_STATE_ADD 1l
static Bool isMapNotify(Display *dpy, XEvent *ev, XPointer win)
static Bool
isMapNotify(Display *dpy, XEvent *ev, XPointer win) /* NOLINT(readability-non-const-parameter): cannot make XPointer a const pointer due to typedef */
{
return ev->type == MapNotify && ev->xmap.window == *((Window *)win);
}
static Bool isUnmapNotify(Display *dpy, XEvent *ev, XPointer win)
static Bool
isUnmapNotify(Display *dpy, XEvent *ev, XPointer win) /* NOLINT(readability-non-const-parameter): cannot make XPointer a const pointer due to typedef */
{
return ev->type == UnmapNotify && ev->xunmap.window == *((Window *)win);
}
@@ -586,14 +588,14 @@ int X11_CreateWindow(_THIS, SDL_Window *window)
X11_SetNetWMState(_this, w, window->flags);
compositor = 2; /* don't disable compositing except for "normal" windows */
hint = SDL_GetHint(SDL_HINT_X11_WINDOW_TYPE);
if (window->flags & SDL_WINDOW_UTILITY) {
wintype_name = "_NET_WM_WINDOW_TYPE_UTILITY";
} else if (window->flags & SDL_WINDOW_TOOLTIP) {
wintype_name = "_NET_WM_WINDOW_TYPE_TOOLTIP";
} else if (window->flags & SDL_WINDOW_POPUP_MENU) {
wintype_name = "_NET_WM_WINDOW_TYPE_POPUP_MENU";
} else if (((hint = SDL_GetHint(SDL_HINT_X11_WINDOW_TYPE)) != NULL) && *hint) {
} else if (hint != NULL && *hint) {
wintype_name = hint;
} else {
wintype_name = "_NET_WM_WINDOW_TYPE_NORMAL";
@@ -1555,7 +1557,7 @@ X11_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size)
X11_XGetWindowAttributes(display, data->xwindow, &attributes);
if (X11_XScreenNumberOfScreen(attributes.screen) > 0) {
SDL_snprintf(icc_atom_string, sizeof("_ICC_PROFILE_") + 12, "%s%d", "_ICC_PROFILE_", X11_XScreenNumberOfScreen(attributes.screen));
(void)SDL_snprintf(icc_atom_string, sizeof("_ICC_PROFILE_") + 12, "%s%d", "_ICC_PROFILE_", X11_XScreenNumberOfScreen(attributes.screen));
} else {
SDL_strlcpy(icc_atom_string, "_ICC_PROFILE", sizeof("_ICC_PROFILE"));
}
@@ -1818,7 +1820,7 @@ int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title)
{
Atom _NET_WM_NAME = X11_XInternAtom(display, "_NET_WM_NAME", False);
XTextProperty titleprop;
int conv = X11_XmbTextListToTextProperty(display, (char **)&title, 1, XTextStyle, &titleprop);
int conv = X11_XmbTextListToTextProperty(display, &title, 1, XTextStyle, &titleprop);
Status status;
if (X11_XSupportsLocale() != True) {
@@ -1837,7 +1839,7 @@ int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title)
}
#ifdef X_HAVE_UTF8_STRING
status = X11_Xutf8TextListToTextProperty(display, (char **)&title, 1, XUTF8StringStyle, &titleprop);
status = X11_Xutf8TextListToTextProperty(display, &title, 1, XUTF8StringStyle, &titleprop);
if (status == Success) {
X11_XSetTextProperty(display, xwindow, &titleprop, _NET_WM_NAME);
X11_XFree(titleprop.value);

View File

@@ -117,7 +117,7 @@ extern int X11_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
extern void X11_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept);
extern int X11_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation);
int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *string);
int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title);
#endif /* SDL_x11window_h_ */