Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some compiler warnings in the 2dlib directory #643

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions 2dlib/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,12 @@ inline int READ_FONT_DATA(FONTFILE ffile, void *buf, int size, int nelem) {
}

inline FONTFILE OPEN_FONT(const char *filename, bool &success) {
FONTFILE fp;
int file_id;

success = false;
fp = (FONTFILE)cfopen(filename, "rb");
FONTFILE fp = (FONTFILE)cfopen(filename, "rb");
if (!fp)
return NULL;

file_id = READ_FONT_INT(fp);
uint32_t file_id = READ_FONT_INT(fp);
if (file_id != 0xfeedbaba)
return (FONTFILE)(-1);

Expand Down Expand Up @@ -634,7 +631,7 @@ int grFont::draw_char(grSurface *sf, int x, int y, int ch, tCharProperties *chpr

int grFont::draw_char(grSurface *sf, int x, int y, int ch, int sx, int sy, int sw, int sh, tCharProperties *chprop) {
gr_font_record *ft;
int next_x = 0, width, index;
int next_x = 0, index;

ASSERT(m_FontHandle > -1);
if ((ch < min_ascii()) || (ch > max_ascii()))
Expand All @@ -646,6 +643,7 @@ int grFont::draw_char(grSurface *sf, int x, int y, int ch, int sx, int sy, int s
index = ch - ft->font.min_ascii;

// draw either a color bitmap or mono font.
[[maybe_unused]] int width;
if (ft->font.flags & FT_PROPORTIONAL) {
width = (int)ft->font.char_widths[index];
} else {
Expand Down
5 changes: 2 additions & 3 deletions 2dlib/memsurf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ bool grMemorySurface::init(int w, int h, int bpp, char *data, int rowsize, unsig
// internal functions
// ---------------------------------------------------------------------------

static mem_bitmap grMemSurf_object;

bool gr_bm_mem_Blt16(ddgr_surface *dsf, int dx, int dy, ddgr_surface *ssf, int sx, int sy, int sw, int sh);
bool gr_bm_mem_Blt16ck(ddgr_surface *dsf, int dx, int dy, ddgr_surface *ssf, int sx, int sy, int sw, int sh);

Expand Down Expand Up @@ -267,7 +265,8 @@ void gr_mem_surf_Clear(ddgr_surface *dsf, ddgr_color col, int l, int t, int w, i
bool gr_mem_surf_Blt(ddgr_surface *dsf, int dx, int dy, ddgr_surface *ssf, int sx, int sy, int sw, int sh) {
// Maybe we should allow slow 16bpp to 24bpp and vice-versa blts.
// for now, we wont.
mem_bitmap *sbm = (mem_bitmap *)ssf->obj, *dbm = (mem_bitmap *)dsf->obj;
[[maybe_unused]] mem_bitmap *sbm = (mem_bitmap *)ssf->obj;
mem_bitmap *dbm = (mem_bitmap *)dsf->obj;

ASSERT(dbm->bpp == sbm->bpp);

Expand Down
9 changes: 0 additions & 9 deletions 2dlib/pen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,9 @@ void grViewport::hline(ddgr_color col, int x1, int x2, int y1) {
rend_DrawLine(x1, y1, x2, y1);
}

// grViewport::line
// draws a clipped line

void grViewport::line(ddgr_color color, int x1, int y1, int x2, int y2) {
int xa, ya, xb, yb;
ASSERT(vp_Locked);

xa = global_x(x1);
ya = global_y(y1);
xb = global_x(x2);
yb = global_y(y2);

rend_SetFlatColor(color);
rend_DrawLine(x1, y1, x2, y2);
}
Expand Down
16 changes: 5 additions & 11 deletions 2dlib/pentext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@

#define STR_BUF_SIZE 512
static char Str_buf[STR_BUF_SIZE]; // String buffer for variable arguments
static char Draw_str_buf[STR_BUF_SIZE]; // used to buffer words in a string

// ---------------------------------------------------------------------------
// Viewport font and text funcitons
Expand Down Expand Up @@ -334,23 +333,18 @@ void grViewport::draw_text_line_clip(int x, int y, char *str) {
}

void grViewport::draw_text_line(int x, int y, char *str) {
unsigned i, cur_x;

/* perform string drawing without viewport clipping.
supports bitmap fonts or color(alpha) mapped fonts.
*/
cur_x = x;
for (i = 0; i < (int)strlen(str); i++) {
uint8_t ch;

ch = (uint8_t)str[i];

uint32_t cur_x = x;
for (size_t i = 0; i < strlen(str); i++) {
uint8_t ch = (uint8_t)str[i];
if (ch == GR_COLOR_CHAR) {
if ((i + 3) >= (int)strlen(str))
if ((i + 3) >= strlen(str))
Int3(); // This shouldn't happen! bad string!
set_text_color(GR_RGB(str[i + 1], str[i + 2], str[i + 3]));
i += 4;
if (i >= (int)strlen(str))
if (i >= strlen(str))
Int3(); // This shouldn't happen too.
ch = (uint8_t)str[i];
} else if (ch == '\t') { // tab char
Expand Down
21 changes: 8 additions & 13 deletions 2dlib/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
case SURFTYPE_MEMORY:
grerr = (bool)gr_mem_surf_Create(&ddsfObj);
break;
default:

Check warning on line 177 in 2dlib/surface.cpp

View workflow job for this annotation

GitHub Actions / Linux-x64-clang, Release

variable 'grerr' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
Int3(); // Invalid!!
}
if (!grerr)
Expand Down Expand Up @@ -319,7 +319,6 @@
// mode 11b = dd_to_dd, 01b = mem_to_dd, 10b = dd_to_mem, 00b = mem_to_mem
int mode = 0;
ddgr_surface *dsfs = &ddsfObj, *ssfs = &ssf->ddsfObj;
bool err;

// setup blitting mode
if (ssfs->type == SURFTYPE_GENERIC || ssfs->type == SURFTYPE_VIDEOSCREEN)
Expand All @@ -332,15 +331,15 @@
*/
if (mode == 0x3) {
ASSERT(!surf_Locked);
err = ddgr_surf_Blt(dsfs, dx, dy, ssfs, sx, sy, sw, sh);
ddgr_surf_Blt(dsfs, dx, dy, ssfs, sx, sy, sw, sh);
return;
}

/* case 2: mem->mem
just lock both surfaces and do a memory blt.
*/
if (mode == 0) {
err = gr_mem_surf_Blt(dsfs, dx, dy, ssfs, sx, sy, sw, sh);
gr_mem_surf_Blt(dsfs, dx, dy, ssfs, sx, sy, sw, sh);
return;
}

Expand All @@ -359,7 +358,7 @@
grSurface::scratch_mem_surf->flags = ssfs->flags;

gr_mem_surf_Init(grSurface::scratch_mem_surf, data, rowsize);
err = gr_mem_surf_Blt(dsfs, dx, dy, grSurface::scratch_mem_surf, sx, sy, sw, sh);
gr_mem_surf_Blt(dsfs, dx, dy, grSurface::scratch_mem_surf, sx, sy, sw, sh);

ssf->unlock();
return;
Expand All @@ -380,7 +379,7 @@
grSurface::scratch_mem_surf->flags = dsfs->flags;

gr_mem_surf_Init(grSurface::scratch_mem_surf, m_DataPtr, m_DataRowsize);
err = gr_mem_surf_Blt(grSurface::scratch_mem_surf, dx, dy, ssfs, sx, sy, sw, sh);
gr_mem_surf_Blt(grSurface::scratch_mem_surf, dx, dy, ssfs, sx, sy, sw, sh);

grSurface::unlock();
return;
Expand Down Expand Up @@ -436,10 +435,9 @@
// ---------------------------------------------------------------------------

char *grSurface::lock(int *rowsize) {
bool grerr;

ASSERT(m_SurfInit);

bool grerr = false;
switch (ddsfObj.type) {
case SURFTYPE_VIDEOSCREEN:
case SURFTYPE_GENERIC:
Expand Down Expand Up @@ -513,18 +511,16 @@
}

void grSurface::unlock() {
bool grerr;

ASSERT(m_SurfInit);
ASSERT(surf_Locked);

switch (ddsfObj.type) {
case SURFTYPE_VIDEOSCREEN:
case SURFTYPE_GENERIC:
grerr = ddgr_surf_Unlock(&ddsfObj, m_OrigDataPtr);
ddgr_surf_Unlock(&ddsfObj, m_OrigDataPtr);
break;
case SURFTYPE_MEMORY:
grerr = gr_mem_surf_Unlock(&ddsfObj, m_OrigDataPtr);
gr_mem_surf_Unlock(&ddsfObj, m_OrigDataPtr);
break;
default:
Int3(); // invalid type!!
Expand Down Expand Up @@ -670,11 +666,10 @@
char *sptr;
uint16_t *dptr;
int scol, dcol, row;
int rowsize_w, height, width;
int height, width;

dptr = (uint16_t *)m_DataPtr;
sptr = (char *)data;
rowsize_w = m_DataRowsize / 2;
height = std::min(h, ddsfObj.h);
width = std::min(w, ddsfObj.w);

Expand Down
Loading