Skip to content

Commit dcf6cc7

Browse files
committed
Warning fixes #2
1 parent 7a8fd93 commit dcf6cc7

13 files changed

Lines changed: 55 additions & 43 deletions

File tree

configuration.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5436,7 +5436,7 @@ void input_config_get_prefix(char *s, char len, char user, bool meta)
54365436
*/
54375437
static void input_config_save_keybinds_user(config_file_t *conf, unsigned user)
54385438
{
5439-
size_t i = 0;
5439+
unsigned i;
54405440
for (i = 0; input_config_bind_map_get_valid(i); i++)
54415441
{
54425442
char key[64];
@@ -5482,7 +5482,7 @@ static void input_config_save_keybinds_user_override(config_file_t *conf,
54825482
unsigned user, unsigned bind_id,
54835483
const struct retro_keybind *override_bind)
54845484
{
5485-
size_t i = bind_id;
5485+
unsigned i = bind_id;
54865486

54875487
if (input_config_bind_map_get_valid(i))
54885488
{
@@ -5533,7 +5533,7 @@ static void input_config_save_keybinds_user_override(config_file_t *conf,
55335533
static void input_config_save_keybinds_user_minimal(config_file_t *conf,
55345534
unsigned user, const retro_keybind_set default_binds)
55355535
{
5536-
size_t i = 0;
5536+
unsigned i;
55375537
for (i = 0; input_config_bind_map_get_valid(i); i++)
55385538
{
55395539
char key[64];

gfx/drivers_shader/slang_cache.cpp

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <stdlib.h>
66
#include <string.h>
7+
#include <stdint.h>
78
#include <file/file_path.h>
89
#include <streams/file_stream.h>
910
#include <vfs/vfs.h>
@@ -83,12 +84,15 @@ static bool spirv_cache_get_filename(const char *hash,
8384
*/
8485
static bool spirv_cache_write_string(RFILE *file, const std::string &str)
8586
{
86-
uint32_t len = str.length();
87+
uint32_t _len;
88+
if (str.length() > UINT32_MAX)
89+
return false;
90+
_len = (uint32_t)str.length();
8791

88-
if (filestream_write(file, &len, sizeof(uint32_t)) != sizeof(uint32_t))
92+
if (filestream_write(file, &_len, sizeof(uint32_t)) != sizeof(uint32_t))
8993
return false;
9094

91-
if (len > 0 && filestream_write(file, str.c_str(), len) != len)
95+
if (_len > 0 && filestream_write(file, str.c_str(), _len) != _len)
9296
return false;
9397

9498
return true;
@@ -103,29 +107,30 @@ static bool spirv_cache_write_string(RFILE *file, const std::string &str)
103107
*/
104108
static bool spirv_cache_read_string(RFILE *file, std::string &str_out)
105109
{
106-
uint32_t len;
110+
uint32_t _len;
111+
char *buf;
107112

108-
if (filestream_read(file, &len, sizeof(uint32_t)) != sizeof(uint32_t))
113+
if (filestream_read(file, &_len, sizeof(uint32_t)) != sizeof(uint32_t))
109114
return false;
110115

111-
if (len == 0)
116+
if (_len == 0)
112117
{
113118
str_out.clear();
114119
return true;
115120
}
116121

117122
/* Allocate and read string */
118-
char *buf = new char[len + 1];
123+
buf = new char[_len + 1];
119124
if (!buf)
120125
return false;
121126

122-
if (filestream_read(file, buf, len) != len)
127+
if (filestream_read(file, buf, _len) != _len)
123128
{
124129
delete[] buf;
125130
return false;
126131
}
127132

128-
buf[len] = '\0';
133+
buf[_len] = '\0';
129134
str_out = buf;
130135
delete[] buf;
131136

@@ -134,18 +139,18 @@ static bool spirv_cache_read_string(RFILE *file, std::string &str_out)
134139

135140
extern "C" {
136141

137-
bool spirv_cache_compute_hash(const char *vertex_source, const char *fragment_source,
138-
char *hash_out)
142+
bool spirv_cache_compute_hash(const char *vertex_source, const char *fragment_source, char *hash_out)
139143
{
144+
uint8_t *combined;
145+
size_t vertex_len, fragment_len, total_len;
140146
if (!vertex_source || !fragment_source || !hash_out)
141147
return false;
142148

143149
/* Build combined hash input: vertex + "|" + fragment */
144-
size_t vertex_len = strlen(vertex_source);
145-
size_t fragment_len = strlen(fragment_source);
146-
size_t total_len = vertex_len + 1 + fragment_len; /* 1 for "|" separator */
147-
148-
uint8_t *combined = new uint8_t[total_len];
150+
vertex_len = strlen(vertex_source);
151+
fragment_len = strlen(fragment_source);
152+
total_len = vertex_len + 1 + fragment_len; /* 1 for "|" separator */
153+
combined = new uint8_t[total_len];
149154
if (!combined)
150155
return false;
151156

@@ -163,8 +168,8 @@ bool spirv_cache_compute_hash(const char *vertex_source, const char *fragment_so
163168
bool spirv_cache_load(const char *hash, struct glslang_output *output)
164169
{
165170
RFILE *file;
166-
char cache_file[PATH_MAX_LENGTH];
167171
uint8_t version;
172+
char cache_file[PATH_MAX_LENGTH];
168173
uint32_t vertex_size, fragment_size, param_count, i;
169174
uint16_t rt_format;
170175

@@ -259,10 +264,10 @@ bool spirv_cache_load(const char *hash, struct glslang_output *output)
259264
bool spirv_cache_save(const char *hash, const struct glslang_output *output)
260265
{
261266
RFILE *file;
267+
uint16_t rt_format;
262268
char cache_file[PATH_MAX_LENGTH];
263269
uint8_t version = SPIRV_CACHE_VERSION;
264270
uint32_t vertex_size, fragment_size, param_count, i;
265-
uint16_t rt_format;
266271

267272
if (!hash || !output)
268273
return false;
@@ -284,7 +289,9 @@ bool spirv_cache_save(const char *hash, const struct glslang_output *output)
284289
goto error;
285290

286291
/* Write vertex SPIR-V */
287-
vertex_size = output->vertex.size();
292+
if (output->vertex.size() > UINT32_MAX)
293+
goto error;
294+
vertex_size = (uint32_t)output->vertex.size();
288295
if (filestream_write(file, &vertex_size, sizeof(uint32_t)) != sizeof(uint32_t))
289296
goto error;
290297
if (vertex_size > 0)
@@ -294,7 +301,9 @@ bool spirv_cache_save(const char *hash, const struct glslang_output *output)
294301
}
295302

296303
/* Write fragment SPIR-V */
297-
fragment_size = output->fragment.size();
304+
if (output->fragment.size() > UINT32_MAX)
305+
goto error;
306+
fragment_size = (uint32_t)output->fragment.size();
298307
if (filestream_write(file, &fragment_size, sizeof(uint32_t)) != sizeof(uint32_t))
299308
goto error;
300309
if (fragment_size > 0)
@@ -304,7 +313,9 @@ bool spirv_cache_save(const char *hash, const struct glslang_output *output)
304313
}
305314

306315
/* Write parameters */
307-
param_count = output->meta.parameters.size();
316+
if (output->meta.parameters.size() > UINT32_MAX)
317+
goto error;
318+
param_count = (uint32_t)output->meta.parameters.size();
308319
if (filestream_write(file, &param_count, sizeof(uint32_t)) != sizeof(uint32_t))
309320
goto error;
310321

libretro-common/vfs/vfs_implementation_smb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static bool smb_initialized = false;
3636
static int max_context_configured = 0;
3737
static const struct smb_settings *smb_cfg = NULL;
3838

39-
static struct smb2_context *get_smb_context()
39+
static struct smb2_context *get_smb_context(void)
4040
{
4141
int idx;
4242

@@ -81,7 +81,7 @@ bool smb_init_cfg(const struct smb_settings *new_cfg)
8181
}
8282

8383
/* Initialize SMB context */
84-
static bool smb_init()
84+
static bool smb_init(void)
8585
{
8686
char server[256];
8787
char share[256];
@@ -220,7 +220,7 @@ void smb_close_context(int index)
220220
}
221221

222222
/* Shutdown SMB context - called on exit */
223-
void smb_shutdown()
223+
void smb_shutdown(void)
224224
{
225225
int i;
226226

libretro-common/vfs/vfs_implementation_smb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int retro_vfs_stat_smb(const char *path, int64_t *size);
6666
int retro_vfs_file_error_smb(libretro_vfs_implementation_file *stream);
6767

6868
/* Context management */
69-
void smb_shutdown();
69+
void smb_shutdown(void);
7070

7171
#ifdef __cplusplus
7272
}

menu/drivers/materialui.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10784,7 +10784,6 @@ static int materialui_pointer_down(void *userdata,
1078410784
int drag_margin_vert;
1078510785
gfx_display_t *p_disp = disp_get_ptr();
1078610786
unsigned header_height = p_disp->header_height;
10787-
unsigned width = mui->last_width;
1078810787
unsigned height = mui->last_height;
1078910788

1079010789
/* Check whether pointer down event is within

menu/drivers/ozone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7458,7 +7458,7 @@ static void ozone_draw_messagebox(
74587458
unsigned slice_new_w = longest_width + (slice_margin * 2);
74597459
unsigned slice_new_h = line_height * (line_count + 2) + (slice_margin / 2);
74607460
unsigned slice_w = 256;
7461-
int slice_x = x - (longest_width / 2) - slice_margin;
7461+
int slice_x = (int)(x - (longest_width / 2) - slice_margin);
74627462
int slice_y = y - line_height - (slice_margin / 4)
74637463
+ ((slice_new_h >= slice_w)
74647464
? (16.0f * scale_factor)

menu/drivers/rgui.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,7 @@ static void rgui_render_mini_thumbnail(
29722972
else
29732973
fb_y_offset = (rgui->term_layout.start_y + term_height) - thumbnail->max_height;
29742974

2975-
text_x = (thumbnail->max_width / 2) + fb_x_offset - (strlen(msg) * (rgui->font_width_stride / 2));
2975+
text_x = (thumbnail->max_width / 2) + fb_x_offset - ((int)strlen(msg) * (rgui->font_width_stride / 2));
29762976
text_y = (thumbnail->max_height / 2) + fb_y_offset - (rgui->font_height_stride / 3);
29772977

29782978
/* Draw background */
@@ -5543,9 +5543,9 @@ static void rgui_render(void *data, unsigned width, unsigned height,
55435543

55445544
rgui_blit_line(rgui,
55455545
fb_width,
5546-
term_end_x
5546+
(int)(term_end_x
55475547
- (powerstate_len * rgui->font_width_stride)
5548-
- (timedate_len * rgui->font_width_stride),
5548+
- (timedate_len * rgui->font_width_stride)),
55495549
title_y,
55505550
timedate,
55515551
rgui->colors.hover_color,

menu/drivers/xmb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,7 @@ static void xmb_set_title(xmb_handle_t *xmb)
25492549
if (xmb->categories_selection_ptr > xmb->system_tab_end)
25502550
{
25512551
xmb_node_t *sidebar_node = NULL;
2552-
int i = xmb->categories_selection_ptr - xmb->system_tab_end - 1;
2552+
size_t i = xmb->categories_selection_ptr - xmb->system_tab_end - 1;
25532553

25542554
/* Explore views */
25552555
if (string_ends_with_size(xmb->horizontal_list.list[i].label, ".lvw",

retroarch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ static size_t find_driver_nonempty(
12611261

12621262
int driver_find_index(const char *label, const char *drv)
12631263
{
1264-
size_t i;
1264+
int i;
12651265
char str[NAME_MAX_LENGTH];
12661266

12671267
str[0] = '\0';
@@ -1288,7 +1288,7 @@ int driver_find_index(const char *label, const char *drv)
12881288
**/
12891289
static void driver_find_last(const char *label, char *s, size_t len)
12901290
{
1291-
size_t i;
1291+
int i;
12921292
for (i = 0;
12931293
find_driver_nonempty(label, i, s, len) > 0; i++) { }
12941294
if (i)
@@ -1805,7 +1805,7 @@ void drivers_init(
18051805
#endif
18061806

18071807
#ifdef HAVE_MENU
1808-
srand(time(NULL));
1808+
srand((unsigned)time(NULL));
18091809
#endif
18101810
}
18111811

@@ -5408,7 +5408,7 @@ bool command_event(enum event_command cmd, void *data)
54085408
break;
54095409
case CMD_EVENT_RUMBLE_STOP:
54105410
{
5411-
size_t i;
5411+
unsigned i;
54125412
for (i = 0; i < MAX_USERS; i++)
54135413
{
54145414
unsigned joy_idx = settings->uints.input_joypad_index[i];

runahead.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ static INLINE void preempt_input_poll(preempt_t *preempt,
16121612
for (p = 0; p < max_users; p++)
16131613
{
16141614
/* Check full digital joypad */
1615-
int16_t joypad_state = (int16_t)(state_cb(p, RETRO_DEVICE_JOYPAD,
1615+
int16_t joypad_state = (int16_t)(state_cb((unsigned)p, RETRO_DEVICE_JOYPAD,
16161616
0, RETRO_DEVICE_ID_JOYPAD_MASK));
16171617
if (joypad_state != preempt->joypad_state[p])
16181618
{

0 commit comments

Comments
 (0)