diff --git a/SourceS/sdl2_to_1_2_backports.h b/SourceS/sdl2_to_1_2_backports.h index 3ebc5e9cb..52aff1afe 100644 --- a/SourceS/sdl2_to_1_2_backports.h +++ b/SourceS/sdl2_to_1_2_backports.h @@ -603,25 +603,34 @@ SDL_UpperBlitScaled(SDL_Surface *src, SDL_Rect *srcrect, dst_y0 += dst->clip_rect.y; dst_y1 += dst->clip_rect.y; - final_src.x = (int)SDL_floor(src_x0 + 0.5); - final_src.y = (int)SDL_floor(src_y0 + 0.5); - final_src.w = (int)SDL_floor(src_x1 + 1 + 0.5) - (int)SDL_floor(src_x0 + 0.5); - final_src.h = (int)SDL_floor(src_y1 + 1 + 0.5) - (int)SDL_floor(src_y0 + 0.5); - - final_dst.x = (int)SDL_floor(dst_x0 + 0.5); - final_dst.y = (int)SDL_floor(dst_y0 + 0.5); - final_dst.w = (int)SDL_floor(dst_x1 - dst_x0 + 1.5); - final_dst.h = (int)SDL_floor(dst_y1 - dst_y0 + 1.5); - - if (final_dst.w < 0) - final_dst.w = 0; - if (final_dst.h < 0) - final_dst.h = 0; + final_src.x = (Sint16)SDL_floor(src_x0 + 0.5); + final_src.y = (Sint16)SDL_floor(src_y0 + 0.5); + src_w = (int)SDL_floor(src_x1 + 1 + 0.5) - (int)SDL_floor(src_x0 + 0.5); + src_h = (int)SDL_floor(src_y1 + 1 + 0.5) - (int)SDL_floor(src_y0 + 0.5); + if (src_w < 0) + src_w = 0; + if (src_h < 0) + src_h = 0; + + final_src.w = static_cast(src_w); + final_src.h = static_cast(src_h); + + final_dst.x = (Sint16)SDL_floor(dst_x0 + 0.5); + final_dst.y = (Sint16)SDL_floor(dst_y0 + 0.5); + dst_w = (int)SDL_floor(dst_x1 - dst_x0 + 1.5); + dst_h = (int)SDL_floor(dst_y1 - dst_y0 + 1.5); + if (dst_w < 0) + dst_w = 0; + if (dst_h < 0) + dst_h = 0; + + final_dst.w = static_cast(dst_w); + final_dst.h = static_cast(dst_h); if (dstrect) *dstrect = final_dst; - if (final_dst.w == 0 || final_dst.h == 0 || final_src.w <= 0 || final_src.h <= 0) { + if (final_dst.w == 0 || final_dst.h == 0 || final_src.w == 0 || final_src.h == 0) { /* No-op. */ return 0; } @@ -774,7 +783,7 @@ inline char *SDL_GetBasePath() const int rc = (int)SDL_snprintf(path, sizeof(path), "/proc/%llu/exe", (unsigned long long)getpid()); - if ((rc > 0) && (rc < sizeof(path))) { + if ((rc > 0) && (static_cast(rc) < sizeof(path))) { retval = readSymLink(path); } } diff --git a/SourceX/DiabloUI/credits.cpp b/SourceX/DiabloUI/credits.cpp index a2b6032f4..d286fdbe7 100644 --- a/SourceX/DiabloUI/credits.cpp +++ b/SourceX/DiabloUI/credits.cpp @@ -513,7 +513,7 @@ void credts_Render() int offset = 0; int x = 31; - int y = (i * lineHeight) - ybase - lineHeight; + const int y = (i * lineHeight) - ybase - lineHeight; if (*the_long_credits[creditLine + i] == ' ') { offset = 1; x += 40; @@ -522,16 +522,29 @@ void credts_Render() text_surface = TTF_RenderUTF8_Solid(font, the_long_credits[creditLine + i] + offset, color); shadow_surface = TTF_RenderUTF8_Solid(font, the_long_credits[creditLine + i] + offset, black_color); if (text_surface && shadow_surface) { - SDL_Rect src_rect = { 0, -y, text_surface->w, 251 }; + SDL_Rect src_rect = { + 0, + static_cast(-y), + static_cast(text_surface->w), + 251 + }; // draw text shadow. - SDL_Rect dsc_rect2 = { 64 + x + 2, SCREEN_Y + 114 + 2, src_rect.w, src_rect.h }; + SDL_Rect dsc_rect2 = { + static_cast(SCREEN_X + x + 2), + SCREEN_Y + 114 + 2, + src_rect.w, src_rect.h + }; if (SDL_BlitSurface(shadow_surface, &src_rect, pal_surface, &dsc_rect2) <= -1) { SDL_Log(SDL_GetError()); } // draw text. - SDL_Rect dsc_rect = { 64 + x, SCREEN_Y + 114, src_rect.w, src_rect.h }; + SDL_Rect dsc_rect = { + static_cast(SCREEN_X + x), + SCREEN_Y + 114, + src_rect.w, src_rect.h + }; if (SDL_BlitSurface(text_surface, &src_rect, pal_surface, &dsc_rect) <= -1) { SDL_Log(SDL_GetError()); } diff --git a/SourceX/dx.cpp b/SourceX/dx.cpp index 71026c278..176cf7dc3 100644 --- a/SourceX/dx.cpp +++ b/SourceX/dx.cpp @@ -192,11 +192,18 @@ HRESULT CreatePalette() HRESULT BltFast(DWORD dwX, DWORD dwY, LPRECT lpSrcRect) { - int w = lpSrcRect->right - lpSrcRect->left + 1; - int h = lpSrcRect->bottom - lpSrcRect->top + 1; - - SDL_Rect src_rect = { lpSrcRect->left, lpSrcRect->top, w, h }; - SDL_Rect dst_rect = { (int)dwX, (int)dwY, w, h }; + auto w = static_cast(lpSrcRect->right - lpSrcRect->left + 1); + auto h = static_cast(lpSrcRect->bottom - lpSrcRect->top + 1); + SDL_Rect src_rect = { + static_cast(lpSrcRect->left), + static_cast(lpSrcRect->top), + w, h + }; + SDL_Rect dst_rect = { + static_cast(dwX), + static_cast(dwY), + w, h + }; // Convert from 8-bit to 32-bit if (SDL_BlitSurface(pal_surface, &src_rect, surface, &dst_rect) <= -1) { diff --git a/SourceX/storm/storm.cpp b/SourceX/storm/storm.cpp index 94ca620cb..7371cb62e 100644 --- a/SourceX/storm/storm.cpp +++ b/SourceX/storm/storm.cpp @@ -21,10 +21,10 @@ bool directFileAccess = false; static std::string getIniPath() { - char path[DVL_MAX_PATH], file_path[DVL_MAX_PATH]; + char path[DVL_MAX_PATH], file_path[DVL_MAX_PATH + 10]; GetPrefPath(path, DVL_MAX_PATH); - snprintf(file_path, DVL_MAX_PATH, "%sdiablo.ini", path); + snprintf(file_path, DVL_MAX_PATH + 10, "%sdiablo.ini", path); return file_path; } @@ -487,7 +487,7 @@ private: { AudioQueueItem *item; while ((item = Next()) != NULL) { - if (out_len <= item->len) { + if (static_cast(out_len) <= item->len) { SDL_MixAudio(out, item->pos, out_len, SDL_MIX_MAXVOLUME); item->pos += out_len; item->len -= out_len; @@ -721,10 +721,15 @@ BOOL SVidPlayContinue(void) } else { factor = wFactor; } - int scaledW = SVidWidth * factor; - int scaledH = SVidHeight * factor; - - SDL_Rect pal_surface_offset = { (SCREEN_WIDTH - scaledW) / 2, (SCREEN_HEIGHT - scaledH) / 2, scaledW, scaledH }; + const int scaledW = SVidWidth * factor; + const int scaledH = SVidHeight * factor; + + SDL_Rect pal_surface_offset = { + static_cast((SCREEN_WIDTH - scaledW) / 2), + static_cast((SCREEN_HEIGHT - scaledH) / 2), + static_cast(scaledW), + static_cast(scaledH) + }; #ifdef USE_SDL1 SDL_Surface *tmp = SDL_ConvertSurface(SVidSurface, window->format, 0); // NOTE: Consider resolution switching instead if video doesn't play