Skip to content

Commit

Permalink
use strlcpy_literal for string literal copies
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Sep 19, 2020
1 parent 7b600d4 commit 1296fc4
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 66 deletions.
2 changes: 1 addition & 1 deletion database_info.c
Expand Up @@ -37,7 +37,7 @@ int database_info_build_query_enum(char *s, size_t len,
bool add_quotes = true;
bool add_glob = false;

strlcpy(s, "{'", len);
strcpy_literal(s, "{'");

switch (type)
{
Expand Down
54 changes: 27 additions & 27 deletions frontend/frontend_driver.c
Expand Up @@ -172,56 +172,56 @@ bool frontend_driver_get_core_extension(char *s, size_t len)
#ifdef HAVE_DYNAMIC

#ifdef _WIN32
strlcpy(s, "dll", len);
strcpy_literal(s, "dll");
return true;
#elif defined(__APPLE__) || defined(__MACH__)
strlcpy(s, "dylib", len);
strcpy_literal(s, "dylib");
return true;
#else
strlcpy(s, "so", len);
strcpy_literal(s, "so");
return true;
#endif

#else

#if defined(__CELLOS_LV2__)
strlcpy(s, "self|bin", len);
strcpy_literal(s, "self|bin");
return true;
#elif defined(PSP)
strlcpy(s, "pbp", len);
strcpy_literal(s, "pbp");
return true;
#elif defined(VITA)
strlcpy(s, "self|bin", len);
strcpy_literal(s, "self|bin");
return true;
#elif defined(PS2)
strlcpy(s, "elf", len);
strcpy_literal(s, "elf");
return true;
#elif defined(_XBOX1)
strlcpy(s, "xbe", len);
strcpy_literal(s, "xbe");
return true;
#elif defined(_XBOX360)
strlcpy(s, "xex", len);
strcpy_literal(s, "xex");
return true;
#elif defined(GEKKO)
strlcpy(s, "dol", len);
strcpy_literal(s, "dol");
return true;
#elif defined(HW_WUP)
strlcpy(s, "rpx|elf", len);
strcpy_literal(s, "rpx|elf");
return true;
#elif defined(__linux__)
strlcpy(s, "elf", len);
strcpy_literal(s, "elf");
return true;
#elif defined(HAVE_LIBNX)
strlcpy(s, "nro", len);
strcpy_literal(s, "nro");
return true;
#elif defined(DJGPP)
strlcpy(s, "exe", len);
strcpy_literal(s, "exe");
return true;
#elif defined(_3DS)
if (envIsHomebrew())
strlcpy(s, "3dsx", len);
strcpy_literal(s, "3dsx");
else
strlcpy(s, "cia", len);
strcpy_literal(s, "cia");
return true;
#else
return false;
Expand All @@ -237,37 +237,37 @@ bool frontend_driver_get_salamander_basename(char *s, size_t len)
#else

#if defined(__CELLOS_LV2__)
strlcpy(s, "EBOOT.BIN", len);
strcpy_literal(s, "EBOOT.BIN");
return true;
#elif defined(PSP)
strlcpy(s, "EBOOT.PBP", len);
strcpy_literal(s, "EBOOT.PBP");
return true;
#elif defined(VITA)
strlcpy(s, "eboot.bin", len);
strcpy_literal(s, "eboot.bin");
return true;
#elif defined(PS2)
strlcpy(s, "eboot.elf", len);
strcpy_literal(s, "eboot.elf");
return true;
#elif defined(_XBOX1)
strlcpy(s, "default.xbe", len);
strcpy_literal(s, "default.xbe");
return true;
#elif defined(_XBOX360)
strlcpy(s, "default.xex", len);
strcpy_literal(s, "default.xex");
return true;
#elif defined(HW_RVL)
strlcpy(s, "boot.dol", len);
strcpy_literal(s, "boot.dol");
return true;
#elif defined(HW_WUP)
strlcpy(s, "retroarch.rpx", len);
strcpy_literal(s, "retroarch.rpx");
return true;
#elif defined(_3DS)
strlcpy(s, "retroarch.core", len);
strcpy_literal(s, "retroarch.core");
return true;
#elif defined(DJGPP)
strlcpy(s, "retrodos.exe", len);
strcpy_literal(s, "retrodos.exe");
return true;
#elif defined(SWITCH)
strlcpy(s, "retroarch_switch.nro", len);
strcpy_literal(s, "retroarch_switch.nro");
return true;
#else
return false;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_shader/glslang_util_cxx.cpp
Expand Up @@ -67,7 +67,7 @@ static std::string build_stage_source(

expected[0] = '\0';

strlcpy(expected, "#pragma stage ", sizeof(expected));
strcpy_literal(expected, "#pragma stage ");
strlcat(expected, stage, sizeof(expected));

active = string_is_equal(expected, line);
Expand Down
2 changes: 2 additions & 0 deletions libretro-common/include/string/stdstring.h
Expand Up @@ -35,6 +35,8 @@

RETRO_BEGIN_DECLS

#define strcpy_literal(a, b) strcpy(a, b)

static INLINE bool string_is_empty(const char *data)
{
return !data || (*data == '\0');
Expand Down
20 changes: 10 additions & 10 deletions libretro-db/query.c
Expand Up @@ -290,7 +290,7 @@ static void query_raise_unknown_function(
if (len < (_len - n - 3))
strncpy(s + n, name, len);

strlcpy(s + n + len, "'", _len);
strcpy_literal(s + n + len, "'");
*error = s;
}

Expand Down Expand Up @@ -452,7 +452,7 @@ static struct buffer query_parse_string(

if (!value->val.string.buff)
{
strlcpy(s, "Out of memory", len);
strcpy_literal(s, "Out of memory");
*error = s;
}
else if (is_binstr)
Expand Down Expand Up @@ -692,8 +692,8 @@ static struct buffer query_parse_method_call(
{
if (argi >= QUERY_MAX_ARGS)
{
strlcpy(s,
"Too many arguments in function call.", len);
strcpy_literal(s,
"Too many arguments in function call.");
*error = s;
goto clean;
}
Expand Down Expand Up @@ -725,7 +725,7 @@ static struct buffer query_parse_method_call(

if (!invocation->argv)
{
strlcpy(s, "Out of memory", len);
strcpy_literal(s, "Out of memory");
*error = s;
goto clean;
}
Expand Down Expand Up @@ -817,8 +817,8 @@ static struct buffer query_parse_table(
{
if (argi >= QUERY_MAX_ARGS)
{
strlcpy(s,
"Too many arguments in function call.", len);
strcpy_literal(s,
"Too many arguments in function call.");
*error = s;
goto clean;
}
Expand Down Expand Up @@ -866,8 +866,8 @@ static struct buffer query_parse_table(

if (argi >= QUERY_MAX_ARGS)
{
strlcpy(s,
"Too many arguments in function call.", len);
strcpy_literal(s,
"Too many arguments in function call.");
*error = s;
goto clean;
}
Expand Down Expand Up @@ -900,7 +900,7 @@ static struct buffer query_parse_table(

if (!invocation->argv)
{
strlcpy(s, "Out of memory", len);
strcpy_literal(s, "Out of memory");
*error = s;
goto clean;
}
Expand Down
53 changes: 26 additions & 27 deletions retroarch.c
Expand Up @@ -5525,27 +5525,27 @@ int menu_entries_get_core_title(char *s, size_t len)
: msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE);
const char *core_version = (system && system->library_version) ? system->library_version : "";
#if _MSC_VER == 1200
strlcpy(s, PACKAGE_VERSION " msvc6" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc6" " - ");
#elif _MSC_VER == 1300
strlcpy(s, PACKAGE_VERSION " msvc2002" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc2002" " - ");
#elif _MSC_VER == 1310
strlcpy(s, PACKAGE_VERSION " msvc2003" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc2003" " - ");
#elif _MSC_VER == 1400
strlcpy(s, PACKAGE_VERSION " msvc2005" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc2005" " - ");
#elif _MSC_VER == 1500
strlcpy(s, PACKAGE_VERSION " msvc2008" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc2008" " - ");
#elif _MSC_VER == 1600
strlcpy(s, PACKAGE_VERSION " msvc2010" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc2010" " - ");
#elif _MSC_VER == 1700
strlcpy(s, PACKAGE_VERSION " msvc2012" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc2012" " - ");
#elif _MSC_VER == 1800
strlcpy(s, PACKAGE_VERSION " msvc2013" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc2013" " - ");
#elif _MSC_VER == 1900
strlcpy(s, PACKAGE_VERSION " msvc2015" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc2015" " - ");
#elif _MSC_VER >= 1910 && _MSC_VER < 2000
strlcpy(s, PACKAGE_VERSION " msvc2017" " - ", len);
strcpy_literal(s, PACKAGE_VERSION " msvc2017" " - ");
#else
strlcpy(s, PACKAGE_VERSION " - ", len);
strcpy_literal(s, PACKAGE_VERSION " - ");
#endif
strlcat(s, core_name, len);
if (!string_is_empty(core_version))
Expand Down Expand Up @@ -9165,7 +9165,7 @@ static void discord_init(
strlcat(command, args, sizeof(command));
}
#else
strlcpy(command, "sh -c ", sizeof(command));
strcpy_literal(command, "sh -c ");
strlcat(command, args, sizeof(command));
#endif
RARCH_LOG("[DISCORD]: Registering startup command: %s\n", command);
Expand Down Expand Up @@ -11489,7 +11489,7 @@ static bool path_init_subsystem(struct rarch_state *p_rarch)

path[0] = ext[0] = '\0';

strlcpy(ext, ".", sizeof(ext));
strcpy_literal(ext, ".");
strlcat(ext, mem->extension, sizeof(ext));
strlcpy(savename,
p_rarch->subsystem_fullpaths->elems[i].data,
Expand Down Expand Up @@ -12781,7 +12781,7 @@ static bool command_get_status(const char* arg)
content_get_status(&contentless, &is_inited);

if (!is_inited)
strlcpy(reply, "GET_STATUS CONTENTLESS", sizeof(reply));
strcpy_literal(reply, "GET_STATUS CONTENTLESS");
else
{
/* add some content info */
Expand Down Expand Up @@ -15403,7 +15403,7 @@ static bool command_event_save_config(
msg_hash_to_str(MSG_SAVED_NEW_CONFIG_TO),
config_path);

strlcpy(log, "[config] ", sizeof(log));
strcpy_literal(log, "[config] ");
strlcat(log, s, sizeof(log));
RARCH_LOG("%s\n", log);
return true;
Expand All @@ -15415,7 +15415,7 @@ static bool command_event_save_config(
msg_hash_to_str(MSG_FAILED_SAVING_CONFIG_TO),
str);

strlcpy(log, "[config] ", sizeof(log));
strcpy_literal(log, "[config] ");
strlcat(log, s, sizeof(log));
RARCH_ERR("%s\n", log);
}
Expand Down Expand Up @@ -15545,8 +15545,7 @@ static void command_event_save_current_config(
{
case OVERRIDE_NONE:
if (path_is_empty(RARCH_PATH_CONFIG))
strlcpy(msg, "[config] Config directory not set, cannot save configuration.",
sizeof(msg));
strcpy_literal(msg, "[config] Config directory not set, cannot save configuration.");
else
command_event_save_config(path_get(RARCH_PATH_CONFIG), msg, sizeof(msg));
break;
Expand Down Expand Up @@ -41046,32 +41045,32 @@ const void *frontend_driver_get_cpu_architecture_str(
switch (arch)
{
case FRONTEND_ARCH_X86:
strlcpy(architecture, "x86", size);
strcpy_literal(architecture, "x86");
break;
case FRONTEND_ARCH_X86_64:
strlcpy(architecture, "x64", size);
strcpy_literal(architecture, "x64");
break;
case FRONTEND_ARCH_PPC:
strlcpy(architecture, "PPC", size);
strcpy_literal(architecture, "PPC");
break;
case FRONTEND_ARCH_ARM:
strlcpy(architecture, "ARM", size);
strcpy_literal(architecture, "ARM");
break;
case FRONTEND_ARCH_ARMV7:
strlcpy(architecture, "ARMv7", size);
strcpy_literal(architecture, "ARMv7");
break;
case FRONTEND_ARCH_ARMV8:
strlcpy(architecture, "ARMv8", size);
strcpy_literal(architecture, "ARMv8");
break;
case FRONTEND_ARCH_MIPS:
strlcpy(architecture, "MIPS", size);
strcpy_literal(architecture, "MIPS");
break;
case FRONTEND_ARCH_TILE:
strlcpy(architecture, "Tilera", size);
strcpy_literal(architecture, "Tilera");
break;
case FRONTEND_ARCH_NONE:
default:
strlcpy(architecture, "N/A", size);
strcpy_literal(architecture, "N/A");
break;
}

Expand Down

0 comments on commit 1296fc4

Please sign in to comment.