mirror of
https://github.com/libretro/RetroArch
synced 2025-01-27 21:35:25 +00:00
Small cleanups: * Prevent some unneccessary strlcpy calls and intermediary string copies * Name local length variables for strings '_len', parameter/argument 'len'
This commit is contained in:
parent
0a7b409a04
commit
9d15900979
@ -178,94 +178,36 @@ frontend_ctx_driver_t *frontend_ctx_init_first(void)
|
||||
size_t frontend_driver_get_core_extension(char *s, size_t len)
|
||||
{
|
||||
#ifdef HAVE_DYNAMIC
|
||||
|
||||
#ifdef _WIN32
|
||||
s[0] = 'd';
|
||||
s[1] = 'l';
|
||||
s[2] = 'l';
|
||||
s[3] = '\0';
|
||||
return 3;
|
||||
return strlcpy(s, "dll", len);
|
||||
#elif defined(IOS) || (defined(OSX) && defined(HAVE_APPLE_STORE))
|
||||
s[0] = 'f';
|
||||
s[1] = 'r';
|
||||
s[2] = 'a';
|
||||
s[3] = 'm';
|
||||
s[4] = 'e';
|
||||
s[5] = 'w';
|
||||
s[6] = 'o';
|
||||
s[7] = 'r';
|
||||
s[8] = 'k';
|
||||
s[9] = '\0';
|
||||
return 9;
|
||||
return strlcpy(s, "framework", len);
|
||||
#elif defined(__APPLE__) || defined(__MACH__)
|
||||
s[0] = 'd';
|
||||
s[1] = 'y';
|
||||
s[2] = 'l';
|
||||
s[3] = 'i';
|
||||
s[4] = 'b';
|
||||
s[5] = '\0';
|
||||
return 5;
|
||||
return strlcpy(s, "dylib" ,len);
|
||||
#else
|
||||
s[0] = 's';
|
||||
s[1] = 'o';
|
||||
s[2] = '\0';
|
||||
return 2;
|
||||
return strlcpy(s, "so", len);
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if defined(PSP)
|
||||
s[0] = 'p';
|
||||
s[1] = 'b';
|
||||
s[2] = 'p';
|
||||
s[3] = '\0';
|
||||
return 3;
|
||||
return strlcpy(s, "pbp", len);
|
||||
#elif defined(ORBIS) || defined(VITA) || defined(__PS3__)
|
||||
return strlcpy(s, "self|bin", len);
|
||||
#elif defined(PS2)
|
||||
s[0] = 'e';
|
||||
s[1] = 'l';
|
||||
s[2] = 'f';
|
||||
s[3] = '\0';
|
||||
return 3;
|
||||
return strlcpy(s, "elf", len);
|
||||
#elif defined(_XBOX1)
|
||||
s[0] = 'x';
|
||||
s[1] = 'b';
|
||||
s[2] = 'e';
|
||||
s[3] = '\0';
|
||||
return 3;
|
||||
return strlcpy(s, "xbe", len);
|
||||
#elif defined(_XBOX360)
|
||||
s[0] = 'x';
|
||||
s[1] = 'e';
|
||||
s[2] = 'x';
|
||||
s[3] = '\0';
|
||||
return 3;
|
||||
return strlcpy(s, "xex", len);
|
||||
#elif defined(GEKKO)
|
||||
s[0] = 'd';
|
||||
s[1] = 'o';
|
||||
s[2] = 'l';
|
||||
s[3] = '\0';
|
||||
return 3;
|
||||
return strlcpy(s, "dol", len);
|
||||
#elif defined(HW_WUP)
|
||||
return strlcpy(s, "rpx|elf", len);
|
||||
#elif defined(__linux__)
|
||||
s[0] = 'e';
|
||||
s[1] = 'l';
|
||||
s[2] = 'f';
|
||||
s[3] = '\0';
|
||||
return 3;
|
||||
return strlcpy(s, "elf", len);
|
||||
#elif defined(HAVE_LIBNX)
|
||||
s[0] = 'n';
|
||||
s[1] = 'r';
|
||||
s[2] = 'o';
|
||||
s[3] = '\0';
|
||||
return 3;
|
||||
return strlcpy(s, "nro", len);
|
||||
#elif defined(DJGPP)
|
||||
s[0] = 'e';
|
||||
s[1] = 'x';
|
||||
s[2] = 'e';
|
||||
s[3] = '\0';
|
||||
return 3;
|
||||
return strlcpy(s, "exe", len);
|
||||
#elif defined(_3DS)
|
||||
if (envIsHomebrew())
|
||||
return strlcpy(s, "3dsx", len);
|
||||
|
@ -101,7 +101,7 @@ bool utf16_conv_utf8(uint8_t *out, size_t *out_chars,
|
||||
{
|
||||
size_t out_pos = 0;
|
||||
size_t in_pos = 0;
|
||||
static const
|
||||
static const
|
||||
uint8_t utf8_limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
|
||||
|
||||
for (;;)
|
||||
@ -166,9 +166,9 @@ bool utf16_conv_utf8(uint8_t *out, size_t *out_chars,
|
||||
*
|
||||
* Always NULL terminates. Does not copy half a character.
|
||||
* @s is assumed valid UTF-8.
|
||||
* Use only if @chars is considerably less than @d_len.
|
||||
* Use only if @chars is considerably less than @d_len.
|
||||
*
|
||||
* @return Number of bytes.
|
||||
* @return Number of bytes.
|
||||
**/
|
||||
size_t utf8cpy(char *d, size_t d_len, const char *s, size_t chars)
|
||||
{
|
||||
@ -242,7 +242,7 @@ size_t utf8len(const char *string)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* utf8_walk:
|
||||
*
|
||||
* Does not validate the input.
|
||||
@ -277,13 +277,13 @@ uint32_t utf8_walk(const char **string)
|
||||
static bool utf16_to_char(uint8_t **utf_data,
|
||||
size_t *dest_len, const uint16_t *in)
|
||||
{
|
||||
unsigned len = 0;
|
||||
while (in[len] != '\0')
|
||||
len++;
|
||||
utf16_conv_utf8(NULL, dest_len, in, len);
|
||||
size_t _len = 0;
|
||||
while (in[_len] != '\0')
|
||||
_len++;
|
||||
utf16_conv_utf8(NULL, dest_len, in, _len);
|
||||
*dest_len += 1;
|
||||
if ((*utf_data = (uint8_t*)malloc(*dest_len)) != 0)
|
||||
return utf16_conv_utf8(*utf_data, dest_len, in, len);
|
||||
return utf16_conv_utf8(*utf_data, dest_len, in, _len);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -320,13 +320,13 @@ static char *mb_to_mb_string_alloc(const char *str,
|
||||
wchar_t *path_buf_wide = NULL;
|
||||
int path_buf_wide_len = MultiByteToWideChar(cp_in, 0, str, -1, NULL, 0);
|
||||
|
||||
/* Windows 95 will return 0 from these functions with
|
||||
/* Windows 95 will return 0 from these functions with
|
||||
* a UTF8 codepage set without MSLU.
|
||||
*
|
||||
* From an unknown MSDN version (others omit this info):
|
||||
* - CP_UTF8 Windows 98/Me, Windows NT 4.0 and later:
|
||||
* - CP_UTF8 Windows 98/Me, Windows NT 4.0 and later:
|
||||
* Translate using UTF-8. When this is set, dwFlags must be zero.
|
||||
* - Windows 95: Under the Microsoft Layer for Unicode,
|
||||
* - Windows 95: Under the Microsoft Layer for Unicode,
|
||||
* MultiByteToWideChar also supports CP_UTF7 and CP_UTF8.
|
||||
*/
|
||||
|
||||
@ -412,15 +412,15 @@ char *local_to_utf8_string_alloc(const char *str)
|
||||
|
||||
/**
|
||||
* utf8_to_utf16_string_alloc:
|
||||
*
|
||||
*
|
||||
* @return Returned pointer MUST be freed by the caller if non-NULL.
|
||||
**/
|
||||
wchar_t* utf8_to_utf16_string_alloc(const char *str)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int len = 0;
|
||||
int _len = 0;
|
||||
#else
|
||||
size_t len = 0;
|
||||
size_t _len = 0;
|
||||
#endif
|
||||
wchar_t *buf = NULL;
|
||||
|
||||
@ -428,12 +428,12 @@ wchar_t* utf8_to_utf16_string_alloc(const char *str)
|
||||
return NULL;
|
||||
|
||||
#ifdef _WIN32
|
||||
if ((len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0)))
|
||||
if ((_len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0)))
|
||||
{
|
||||
if (!(buf = (wchar_t*)calloc(len, sizeof(wchar_t))))
|
||||
if (!(buf = (wchar_t*)calloc(_len, sizeof(wchar_t))))
|
||||
return NULL;
|
||||
|
||||
if ((MultiByteToWideChar(CP_UTF8, 0, str, -1, buf, len)) < 0)
|
||||
if ((MultiByteToWideChar(CP_UTF8, 0, str, -1, buf, _len)) < 0)
|
||||
{
|
||||
free(buf);
|
||||
return NULL;
|
||||
@ -442,12 +442,12 @@ wchar_t* utf8_to_utf16_string_alloc(const char *str)
|
||||
else
|
||||
{
|
||||
/* Fallback to ANSI codepage instead */
|
||||
if ((len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0)))
|
||||
if ((_len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0)))
|
||||
{
|
||||
if (!(buf = (wchar_t*)calloc(len, sizeof(wchar_t))))
|
||||
if (!(buf = (wchar_t*)calloc(_len, sizeof(wchar_t))))
|
||||
return NULL;
|
||||
|
||||
if ((MultiByteToWideChar(CP_ACP, 0, str, -1, buf, len)) < 0)
|
||||
if ((MultiByteToWideChar(CP_ACP, 0, str, -1, buf, _len)) < 0)
|
||||
{
|
||||
free(buf);
|
||||
return NULL;
|
||||
@ -456,12 +456,12 @@ wchar_t* utf8_to_utf16_string_alloc(const char *str)
|
||||
}
|
||||
#else
|
||||
/* NOTE: For now, assume non-Windows platforms' locale is already UTF-8. */
|
||||
if ((len = mbstowcs(NULL, str, 0) + 1))
|
||||
if ((_len = mbstowcs(NULL, str, 0) + 1))
|
||||
{
|
||||
if (!(buf = (wchar_t*)calloc(len, sizeof(wchar_t))))
|
||||
if (!(buf = (wchar_t*)calloc(_len, sizeof(wchar_t))))
|
||||
return NULL;
|
||||
|
||||
if ((mbstowcs(buf, str, len)) == (size_t)-1)
|
||||
if ((mbstowcs(buf, str, _len)) == (size_t)-1)
|
||||
{
|
||||
free(buf);
|
||||
return NULL;
|
||||
@ -480,9 +480,9 @@ wchar_t* utf8_to_utf16_string_alloc(const char *str)
|
||||
char* utf16_to_utf8_string_alloc(const wchar_t *str)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int len = 0;
|
||||
int _len = 0;
|
||||
#else
|
||||
size_t len = 0;
|
||||
size_t _len = 0;
|
||||
#endif
|
||||
char *buf = NULL;
|
||||
|
||||
@ -494,33 +494,33 @@ char* utf16_to_utf8_string_alloc(const wchar_t *str)
|
||||
UINT code_page = CP_UTF8;
|
||||
|
||||
/* fallback to ANSI codepage instead */
|
||||
if (!(len = WideCharToMultiByte(code_page,
|
||||
if (!(_len = WideCharToMultiByte(code_page,
|
||||
0, str, -1, NULL, 0, NULL, NULL)))
|
||||
{
|
||||
code_page = CP_ACP;
|
||||
len = WideCharToMultiByte(code_page,
|
||||
_len = WideCharToMultiByte(code_page,
|
||||
0, str, -1, NULL, 0, NULL, NULL);
|
||||
}
|
||||
|
||||
if (!(buf = (char*)calloc(len, sizeof(char))))
|
||||
if (!(buf = (char*)calloc(_len, sizeof(char))))
|
||||
return NULL;
|
||||
|
||||
if (WideCharToMultiByte(code_page,
|
||||
0, str, -1, buf, len, NULL, NULL) < 0)
|
||||
0, str, -1, buf, _len, NULL, NULL) < 0)
|
||||
{
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* NOTE: For now, assume non-Windows platforms'
|
||||
/* NOTE: For now, assume non-Windows platforms'
|
||||
* locale is already UTF-8. */
|
||||
if ((len = wcstombs(NULL, str, 0) + 1))
|
||||
if ((_len = wcstombs(NULL, str, 0) + 1))
|
||||
{
|
||||
if (!(buf = (char*)calloc(len, sizeof(char))))
|
||||
if (!(buf = (char*)calloc(_len, sizeof(char))))
|
||||
return NULL;
|
||||
|
||||
if (wcstombs(buf, str, len) == (size_t)-1)
|
||||
if (wcstombs(buf, str, _len) == (size_t)-1)
|
||||
{
|
||||
free(buf);
|
||||
return NULL;
|
||||
|
@ -421,10 +421,10 @@ static const char *parse_decimal(const char* input,
|
||||
* 2,4-127,128-143
|
||||
* 0-1
|
||||
**/
|
||||
static void cpulist_parse(CpuList* list, char **buf, ssize_t length)
|
||||
static void cpulist_parse(CpuList* list, char **buf, ssize_t len)
|
||||
{
|
||||
const char* p = (const char*)buf;
|
||||
const char* end = p + length;
|
||||
const char* end = p + len;
|
||||
|
||||
/* NOTE: the input line coming from sysfs typically contains a
|
||||
* trailing newline, so take care of it in the code below
|
||||
@ -474,15 +474,15 @@ static void cpulist_parse(CpuList* list, char **buf, ssize_t length)
|
||||
**/
|
||||
static void cpulist_read_from(CpuList* list, const char* filename)
|
||||
{
|
||||
ssize_t length;
|
||||
ssize_t _len;
|
||||
char *buf = NULL;
|
||||
|
||||
list->mask = 0;
|
||||
|
||||
if (filestream_read_file(filename, (void**)&buf, &length) != 1)
|
||||
if (filestream_read_file(filename, (void**)&buf, &_len) != 1)
|
||||
return;
|
||||
|
||||
cpulist_parse(list, &buf, length);
|
||||
cpulist_parse(list, &buf, _len);
|
||||
if (buf)
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
@ -547,15 +547,15 @@ unsigned cpu_features_get_core_amount(void)
|
||||
/* Copypasta from stackoverflow, dunno if it works. */
|
||||
int num_cpu = 0;
|
||||
int mib[4];
|
||||
size_t len = sizeof(num_cpu);
|
||||
size_t _len = sizeof(num_cpu);
|
||||
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_AVAILCPU;
|
||||
sysctl(mib, 2, &num_cpu, &len, NULL, 0);
|
||||
sysctl(mib, 2, &num_cpu, &_len, NULL, 0);
|
||||
if (num_cpu < 1)
|
||||
{
|
||||
mib[1] = HW_NCPU;
|
||||
sysctl(mib, 2, &num_cpu, &len, NULL, 0);
|
||||
sysctl(mib, 2, &num_cpu, &_len, NULL, 0);
|
||||
if (num_cpu < 1)
|
||||
num_cpu = 1;
|
||||
}
|
||||
@ -598,67 +598,53 @@ uint64_t cpu_features_get(void)
|
||||
const int avx_flags = (1 << 27) | (1 << 28);
|
||||
#endif
|
||||
#if defined(__MACH__)
|
||||
size_t len = sizeof(size_t);
|
||||
|
||||
if (sysctlbyname("hw.optional.floatingpoint", NULL, &len, NULL, 0) == 0)
|
||||
size_t _len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.floatingpoint", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_CMOV;
|
||||
|
||||
#if defined(CPU_X86)
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.mmx", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.mmx", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_MMX | RETRO_SIMD_MMXEXT;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_SSE;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse2", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse2", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_SSE2;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse3", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse3", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_SSE3;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.supplementalsse3", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.supplementalsse3", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_SSSE3;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse4_1", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse4_1", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_SSE4;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse4_2", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.sse4_2", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_SSE42;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.aes", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.aes", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_AES;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.avx1_0", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.avx1_0", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_AVX;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.avx2_0", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.avx2_0", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_AVX2;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.altivec", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.altivec", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_VMX;
|
||||
|
||||
#else
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.neon", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.neon", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_NEON;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.neon_fp16", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.neon_fp16", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_VFPV3;
|
||||
|
||||
len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.neon_hpfp", NULL, &len, NULL, 0) == 0)
|
||||
_len = sizeof(size_t);
|
||||
if (sysctlbyname("hw.optional.neon_hpfp", NULL, &_len, NULL, 0) == 0)
|
||||
cpu |= RETRO_SIMD_VFPV4;
|
||||
#endif
|
||||
#elif defined(_XBOX1)
|
||||
@ -803,7 +789,7 @@ uint64_t cpu_features_get(void)
|
||||
return cpu;
|
||||
}
|
||||
|
||||
void cpu_features_get_model_name(char *name, int len)
|
||||
void cpu_features_get_model_name(char *s, int len)
|
||||
{
|
||||
#if defined(CPU_X86) && !defined(__MACH__)
|
||||
union {
|
||||
@ -815,7 +801,7 @@ void cpu_features_get_model_name(char *name, int len)
|
||||
int pos = 0;
|
||||
bool start = false;
|
||||
|
||||
if (!name)
|
||||
if (!s)
|
||||
return;
|
||||
|
||||
x86_cpuid(0x80000000, flags.i);
|
||||
@ -839,26 +825,26 @@ void cpu_features_get_model_name(char *name, int len)
|
||||
if (pos == len - 1)
|
||||
{
|
||||
/* truncate if we ran out of room */
|
||||
name[pos] = '\0';
|
||||
s[pos] = '\0';
|
||||
goto end;
|
||||
}
|
||||
|
||||
name[pos++] = flags.s[j];
|
||||
s[pos++] = flags.s[j];
|
||||
}
|
||||
}
|
||||
end:
|
||||
/* terminate our string */
|
||||
if (pos < len)
|
||||
name[pos] = '\0';
|
||||
s[pos] = '\0';
|
||||
#elif defined(__MACH__)
|
||||
if (!name)
|
||||
if (!s)
|
||||
return;
|
||||
{
|
||||
size_t len_size = len;
|
||||
sysctlbyname("machdep.cpu.brand_string", name, &len_size, NULL, 0);
|
||||
sysctlbyname("machdep.cpu.brand_string", s, &len_size, NULL, 0);
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
if (!name)
|
||||
if (!s)
|
||||
return;
|
||||
{
|
||||
char *model_name, line[128];
|
||||
@ -877,8 +863,8 @@ end:
|
||||
if ((model_name = strstr(line + 10, ": ")))
|
||||
{
|
||||
model_name += 2;
|
||||
strncpy(name, model_name, len);
|
||||
name[len - 1] = '\0';
|
||||
strncpy(s, model_name, len);
|
||||
s[len - 1] = '\0';
|
||||
}
|
||||
|
||||
break;
|
||||
@ -886,9 +872,5 @@ end:
|
||||
|
||||
filestream_close(fp);
|
||||
}
|
||||
#else
|
||||
if (!name)
|
||||
return;
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
@ -164,11 +164,11 @@ char *_mem2_strdup(const char *s)
|
||||
|
||||
if (s)
|
||||
{
|
||||
size_t len = strlen(s) + 1;
|
||||
ptr = _mem2_calloc(1, len);
|
||||
size_t _len = strlen(s) + 1;
|
||||
ptr = _mem2_calloc(1, _len);
|
||||
|
||||
if (ptr)
|
||||
memcpy(ptr, s, len);
|
||||
memcpy(ptr, s, _len);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
@ -180,11 +180,11 @@ char *_mem2_strndup(const char *s, size_t n)
|
||||
|
||||
if (s)
|
||||
{
|
||||
int len = n + 1;
|
||||
ptr = _mem2_calloc(1, len);
|
||||
int _len = n + 1;
|
||||
ptr = _mem2_calloc(1, _len);
|
||||
|
||||
if (ptr)
|
||||
memcpy(ptr, s, len);
|
||||
memcpy(ptr, s, _len);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
@ -612,11 +612,11 @@ static void menu_driver_set_last_start_content(struct menu_state *menu_st, const
|
||||
* archive, must extract the string segment
|
||||
* before the archive delimiter (i.e. path of
|
||||
* 'parent' archive file) */
|
||||
size_t len = (size_t)(1 + archive_delim - start_content_path);
|
||||
if (len >= PATH_MAX_LENGTH)
|
||||
len = PATH_MAX_LENGTH;
|
||||
size_t _len = (size_t)(1 + archive_delim - start_content_path);
|
||||
if (_len >= PATH_MAX_LENGTH)
|
||||
_len = PATH_MAX_LENGTH;
|
||||
|
||||
strlcpy(archive_path, start_content_path, len * sizeof(char));
|
||||
strlcpy(archive_path, start_content_path, _len * sizeof(char));
|
||||
|
||||
file_name = path_basename(archive_path);
|
||||
}
|
||||
|
37
runloop.c
37
runloop.c
@ -1949,7 +1949,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
|
||||
|
||||
if (!string_is_empty(fullpath))
|
||||
{
|
||||
size_t len;
|
||||
size_t _len;
|
||||
char tmp_path[PATH_MAX_LENGTH];
|
||||
|
||||
if (string_is_empty(dir_system))
|
||||
@ -1959,10 +1959,10 @@ bool runloop_environment_cb(unsigned cmd, void *data)
|
||||
fill_pathname_basedir(tmp_path, fullpath, sizeof(tmp_path));
|
||||
|
||||
/* Removes trailing slash (unless root dir) */
|
||||
len = strlen(tmp_path);
|
||||
_len = strlen(tmp_path);
|
||||
if (string_count_occurrences_single_character(tmp_path, PATH_DEFAULT_SLASH_C()) > 1
|
||||
&& tmp_path[len - 1] == PATH_DEFAULT_SLASH_C())
|
||||
tmp_path[len - 1] = '\0';
|
||||
&& tmp_path[_len - 1] == PATH_DEFAULT_SLASH_C())
|
||||
tmp_path[_len - 1] = '\0';
|
||||
|
||||
dir_set(RARCH_DIR_SYSTEM, tmp_path);
|
||||
*(const char**)data = dir_get_ptr(RARCH_DIR_SYSTEM);
|
||||
@ -4595,7 +4595,7 @@ bool runloop_event_init_core(
|
||||
const char *old_savefile_dir,
|
||||
const char *old_savestate_dir)
|
||||
{
|
||||
size_t len;
|
||||
size_t _len;
|
||||
runloop_state_t *runloop_st = &runloop_state;
|
||||
input_driver_state_t *input_st = (input_driver_state_t*)input_data;
|
||||
video_driver_state_t *video_st = video_state_get_ptr();
|
||||
@ -4640,32 +4640,31 @@ bool runloop_event_init_core(
|
||||
if (!sys_info->info.library_version)
|
||||
sys_info->info.library_version = "v0";
|
||||
|
||||
len = strlcpy(
|
||||
_len = strlcpy(
|
||||
video_st->title_buf,
|
||||
msg_hash_to_str(MSG_PROGRAM),
|
||||
sizeof(video_st->title_buf));
|
||||
|
||||
if (!string_is_empty(sys_info->info.library_name))
|
||||
{
|
||||
video_st->title_buf[ len] = ' ';
|
||||
video_st->title_buf[++len] = '\0';
|
||||
len += strlcpy(video_st->title_buf + len,
|
||||
video_st->title_buf[ _len] = ' ';
|
||||
video_st->title_buf[++_len] = '\0';
|
||||
_len += strlcpy(video_st->title_buf + _len,
|
||||
sys_info->info.library_name,
|
||||
sizeof(video_st->title_buf) - len);
|
||||
sizeof(video_st->title_buf) - _len);
|
||||
}
|
||||
|
||||
if (!string_is_empty(sys_info->info.library_version))
|
||||
{
|
||||
video_st->title_buf[ len] = ' ';
|
||||
video_st->title_buf[++len] = '\0';
|
||||
strlcpy(video_st->title_buf + len,
|
||||
video_st->title_buf[ _len] = ' ';
|
||||
video_st->title_buf[++_len] = '\0';
|
||||
strlcpy(video_st->title_buf + _len,
|
||||
sys_info->info.library_version,
|
||||
sizeof(video_st->title_buf) - len);
|
||||
sizeof(video_st->title_buf) - _len);
|
||||
}
|
||||
|
||||
strlcpy(sys_info->valid_extensions,
|
||||
sys_info->info.valid_extensions ?
|
||||
sys_info->info.valid_extensions : DEFAULT_EXT,
|
||||
if (!sys_info->info.valid_extensions)
|
||||
strlcpy(sys_info->valid_extensions, DEFAULT_EXT,
|
||||
sizeof(sys_info->valid_extensions));
|
||||
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
@ -7975,7 +7974,9 @@ void runloop_path_set_redirect(settings_t *settings,
|
||||
RARCH_LOG("%s %s\n",
|
||||
msg_hash_to_str(MSG_REVERTING_SAVEFILE_DIRECTORY_TO),
|
||||
intermediate_savefile_dir);
|
||||
strlcpy(new_savefile_dir, intermediate_savefile_dir, sizeof(new_savefile_dir));
|
||||
strlcpy(new_savefile_dir,
|
||||
intermediate_savefile_dir,
|
||||
sizeof(new_savefile_dir));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -523,9 +523,9 @@ bool task_push_audio_mixer_load_and_play(
|
||||
t->callback = task_audio_mixer_handle_upload_flac_and_play;
|
||||
}
|
||||
else if (
|
||||
string_is_equal(ext_lower, "mod") ||
|
||||
string_is_equal(ext_lower, "s3m") ||
|
||||
string_is_equal(ext_lower, "xm"))
|
||||
string_is_equal(ext_lower, "mod")
|
||||
|| string_is_equal(ext_lower, "s3m")
|
||||
|| string_is_equal(ext_lower, "xm"))
|
||||
{
|
||||
mixer->type = AUDIO_MIXER_TYPE_MOD;
|
||||
nbio->type = NBIO_TYPE_MOD;
|
||||
|
@ -517,15 +517,15 @@ static void handle_translation_cb(
|
||||
{
|
||||
size_t i;
|
||||
char key[8];
|
||||
size_t length = strlen(key_str);
|
||||
size_t _len = strlen(key_str);
|
||||
size_t start = 0;
|
||||
|
||||
for (i = 1; i < length; i++)
|
||||
for (i = 1; i < _len; i++)
|
||||
{
|
||||
char t = key_str[i];
|
||||
if (i == length - 1 || t == ' ' || t == ',')
|
||||
if (i == _len - 1 || t == ' ' || t == ',')
|
||||
{
|
||||
if (i == length - 1 && t != ' ' && t!= ',')
|
||||
if (i == _len - 1 && t != ' ' && t!= ',')
|
||||
i++;
|
||||
|
||||
if (i-start > 7)
|
||||
@ -795,7 +795,7 @@ bool run_translation_service(settings_t *settings, bool paused)
|
||||
char *bmp64_buffer = NULL;
|
||||
rjsonwriter_t *jsonwriter = NULL;
|
||||
const char *json_buffer = NULL;
|
||||
int bmp64_length = 0;
|
||||
int bmp64_len = 0;
|
||||
bool TRANSLATE_USE_BMP = false;
|
||||
char *sys_lbl = NULL;
|
||||
core_info_t *core_info = NULL;
|
||||
@ -967,7 +967,7 @@ bool run_translation_service(settings_t *settings, bool paused)
|
||||
|
||||
if (!(bmp64_buffer = base64((void *)bmp_buffer,
|
||||
(int)(sizeof(uint8_t) * buffer_bytes),
|
||||
&bmp64_length)))
|
||||
&bmp64_len)))
|
||||
goto finish;
|
||||
|
||||
if (!(jsonwriter = rjsonwriter_open_memory()))
|
||||
@ -978,7 +978,7 @@ bool run_translation_service(settings_t *settings, bool paused)
|
||||
rjsonwriter_add_string(jsonwriter, "image");
|
||||
rjsonwriter_raw(jsonwriter, ":", 1);
|
||||
rjsonwriter_raw(jsonwriter, " ", 1);
|
||||
rjsonwriter_add_string_len(jsonwriter, bmp64_buffer, bmp64_length);
|
||||
rjsonwriter_add_string_len(jsonwriter, bmp64_buffer, bmp64_len);
|
||||
|
||||
/* Form request... */
|
||||
if (sys_lbl)
|
||||
@ -1030,7 +1030,7 @@ bool run_translation_service(settings_t *settings, bool paused)
|
||||
|
||||
#ifdef DEBUG
|
||||
if (access_st->ai_service_auto != 2)
|
||||
RARCH_LOG("Request size: %d\n", bmp64_length);
|
||||
RARCH_LOG("Request size: %d\n", bmp64_len);
|
||||
#endif
|
||||
{
|
||||
char new_ai_service_url[PATH_MAX_LENGTH];
|
||||
|
@ -2933,19 +2933,8 @@ void MainWindow::loadContent(const QHash<QString, QString> &contentHash)
|
||||
|
||||
/* Add lpl extension to db_name, if required */
|
||||
if (!string_is_empty(content_db_name))
|
||||
{
|
||||
size_t _len = strlcpy(content_db_name_full, content_db_name,
|
||||
sizeof(content_db_name_full));
|
||||
const char *ext = path_get_extension(content_db_name_full);
|
||||
|
||||
if ( string_is_empty(ext)
|
||||
|| !string_is_equal_noncase(ext,
|
||||
FILE_PATH_LPL_EXTENSION_NO_DOT))
|
||||
strlcpy(
|
||||
content_db_name_full + _len,
|
||||
FILE_PATH_LPL_EXTENSION,
|
||||
sizeof(content_db_name_full) - _len);
|
||||
}
|
||||
fill_pathname(content_db_name_full, content_db_name,
|
||||
".lpl", sizeof(content_db_name_full));
|
||||
|
||||
content_info.argc = 0;
|
||||
content_info.argv = NULL;
|
||||
@ -5280,16 +5269,14 @@ void LoadCoreWindow::onLoadCustomCoreClicked()
|
||||
size_t _len;
|
||||
QString path;
|
||||
QByteArray pathArray;
|
||||
char core_ext[16];
|
||||
char filters[128];
|
||||
const char *pathData = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
const char *path_dir_libretro = settings->paths.directory_libretro;
|
||||
|
||||
frontend_driver_get_core_extension(core_ext, sizeof(core_ext));
|
||||
|
||||
_len = strlcpy(filters, "Cores (*.", sizeof(filters));
|
||||
_len += strlcpy(filters + _len, core_ext, sizeof(filters) - _len);
|
||||
_len += frontend_driver_get_core_extension(filters + _len, sizeof(filters) - _len);
|
||||
strlcpy(filters + _len, ");;All Files (*.*)", sizeof(filters) - _len);
|
||||
|
||||
path = QFileDialog::getOpenFileName(
|
||||
|
Loading…
x
Reference in New Issue
Block a user