Skip to content

Commit 9f9a984

Browse files
committed
Use strlcpy instead of strncpy in places
1 parent 1be2ba8 commit 9f9a984

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

cores/libretro-video-processor/video_processor_v4l2.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <libretro.h>
3535
#include <clamping.h>
36+
#include <compat/strl.h>
3637
#include <retro_miscellaneous.h>
3738

3839
#include <sys/mman.h>
@@ -607,9 +608,9 @@ RETRO_API void VIDEOPROC_CORE_PREFIX(retro_get_system_av_info)(struct retro_syst
607608
info->geometry.base_height = video_format.fmt.pix.height;
608609

609610
if(capture_resolution.value != NULL)
610-
strncpy(video_capture_resolution, capture_resolution.value, ENVVAR_BUFLEN-1);
611+
strlcpy(video_capture_resolution, capture_resolution.value, sizeof(video_capture_resolution));
611612
else
612-
strncpy(video_capture_resolution, "auto", ENVVAR_BUFLEN-1);
613+
strlcpy(video_capture_resolution, "auto", sizeof(video_capture_resolution));
613614

614615
if (strcmp(video_capture_resolution, "auto") != 0)
615616
{
@@ -1047,7 +1048,7 @@ RETRO_API void VIDEOPROC_CORE_PREFIX(retro_run)(void)
10471048
}
10481049

10491050
if (frametimes.value != NULL)
1050-
strncpy(video_frame_times, frametimes.value, ENVVAR_BUFLEN-1);
1051+
strlcpy(video_frame_times, frametimes.value, sizeof(video_frame_times));
10511052
}
10521053

10531054
VIDEOPROC_CORE_PREFIX(input_poll_cb)();
@@ -1217,18 +1218,18 @@ RETRO_API bool VIDEOPROC_CORE_PREFIX(retro_load_game)(const struct retro_game_in
12171218
close_devices();
12181219
return false;
12191220
}
1220-
strncpy(video_device, videodev.value, ENVVAR_BUFLEN-1);
1221+
strlcpy(video_device, videodev.value, sizeof(video_device));
12211222

12221223
/* Audio device is optional... */
12231224
VIDEOPROC_CORE_PREFIX(environment_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &audiodev);
12241225
if (audiodev.value != NULL)
1225-
strncpy(audio_device, audiodev.value, ENVVAR_BUFLEN-1);
1226+
strlcpy(audio_device, audiodev.value, sizeof(audio_device));
12261227

12271228
VIDEOPROC_CORE_PREFIX(environment_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &capture_resolution);
12281229
if(capture_resolution.value != NULL)
1229-
strncpy(video_capture_resolution, capture_resolution.value, ENVVAR_BUFLEN-1);
1230+
strlcpy(video_capture_resolution, capture_resolution.value, sizeof(video_capture_resolution));
12301231
else
1231-
strncpy(video_capture_resolution, "auto", ENVVAR_BUFLEN-1);
1232+
strlcpy(video_capture_resolution, "auto", sizeof(video_capture_resolution));
12321233

12331234
VIDEOPROC_CORE_PREFIX(environment_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &capture_mode);
12341235
VIDEOPROC_CORE_PREFIX(environment_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &output_mode);
@@ -1237,12 +1238,12 @@ RETRO_API bool VIDEOPROC_CORE_PREFIX(retro_load_game)(const struct retro_game_in
12371238
close_devices();
12381239
return false;
12391240
}
1240-
strncpy(video_capture_mode, capture_mode.value, ENVVAR_BUFLEN-1);
1241-
strncpy(video_output_mode, output_mode.value, ENVVAR_BUFLEN-1);
1241+
strlcpy(video_capture_mode, capture_mode.value, sizeof(video_capture_mode));
1242+
strlcpy(video_output_mode, output_mode.value, sizeof(video_output_mode));
12421243

12431244
VIDEOPROC_CORE_PREFIX(environment_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &frame_times);
12441245
if (frame_times.value != NULL)
1245-
strncpy(video_frame_times, frame_times.value, ENVVAR_BUFLEN-1);
1246+
strlcpy(video_frame_times, frame_times.value, sizeof(video_frame_times));
12461247

12471248
if (strcmp(video_device, "dummy") == 0)
12481249
{
@@ -1499,8 +1500,8 @@ RETRO_API bool VIDEOPROC_CORE_PREFIX(retro_load_game)(const struct retro_game_in
14991500

15001501
RETRO_API void VIDEOPROC_CORE_PREFIX(retro_unload_game)(void)
15011502
{
1502-
struct v4l2_requestbuffers reqbufs;
15031503
int i;
1504+
struct v4l2_requestbuffers reqbufs;
15041505

15051506
#ifdef HAVE_ALSA
15061507
if (audio_handle != NULL)

frontend/drivers/platform_darwin.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static void frontend_darwin_get_env(int *argc, char *argv[],
373373
}
374374
#endif
375375
if (portable)
376-
strncpy(documents_dir_buf, application_data, sizeof(documents_dir_buf));
376+
strlcpy(documents_dir_buf, application_data, sizeof(documents_dir_buf));
377377
else
378378
{
379379
CFSearchPathForDirectoriesInDomains(documents_dir_buf, sizeof(documents_dir_buf));
@@ -385,7 +385,7 @@ static void frontend_darwin_get_env(int *argc, char *argv[],
385385
path_resolve_realpath(documents_dir_buf, sizeof(documents_dir_buf), true);
386386
strlcat(documents_dir_buf, "/RetroArch", sizeof(documents_dir_buf));
387387
/* iOS and tvOS are going to put everything in the documents dir */
388-
strncpy(application_data, documents_dir_buf, sizeof(application_data));
388+
strlcpy(application_data, documents_dir_buf, sizeof(application_data));
389389
#endif
390390

391391
/* By the time we are here:

gfx/widgets/gfx_widget_leaderboard_display.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ void gfx_widgets_set_leaderboard_display(unsigned id, const char* value)
458458
if (i == state->tracker_count)
459459
state->tracker_info[state->tracker_count++].id = id;
460460

461-
strncpy(state->tracker_info[i].display, value, sizeof(state->tracker_info[i].display));
461+
strlcpy(state->tracker_info[i].display, value,
462+
sizeof(state->tracker_info[i].display));
462463

463464
{
464465
unsigned width = CHEEVO_LBOARD_DISPLAY_PADDING * 2;

0 commit comments

Comments
 (0)