mirror of
https://github.com/libretro/RetroArch
synced 2025-02-12 09:40:06 +00:00
Merge pull request #12413 from Jamiras/cheevos_sprintf
(cheevos) replace sprintf with snprintf
This commit is contained in:
commit
dd922bfc2c
@ -199,73 +199,79 @@ void rcheevos_log(const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int append_no_spaces(char* buffer, char* stop, const char* text)
|
||||||
|
{
|
||||||
|
char* ptr = buffer;
|
||||||
|
|
||||||
|
while (ptr < stop && *text)
|
||||||
|
{
|
||||||
|
if (*text == ' ')
|
||||||
|
{
|
||||||
|
*ptr++ = '_';
|
||||||
|
++text;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*ptr++ = *text++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*ptr = '\0';
|
||||||
|
return (ptr - buffer);
|
||||||
|
}
|
||||||
|
|
||||||
static void rcheevos_get_user_agent(
|
static void rcheevos_get_user_agent(
|
||||||
rcheevos_locals_t *locals,
|
rcheevos_locals_t *locals,
|
||||||
char *buffer, size_t len)
|
char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
struct retro_system_info *system = runloop_get_libretro_system_info();
|
struct retro_system_info *system = runloop_get_libretro_system_info();
|
||||||
const char* scan;
|
|
||||||
char* ptr;
|
char* ptr;
|
||||||
|
|
||||||
|
/* if we haven't calculated the non-changing portion yet, do so now [retroarch version + os version] */
|
||||||
if (!locals->user_agent_prefix[0])
|
if (!locals->user_agent_prefix[0])
|
||||||
{
|
{
|
||||||
const frontend_ctx_driver_t *frontend = frontend_get_ptr();
|
const frontend_ctx_driver_t *frontend = frontend_get_ptr();
|
||||||
int major, minor;
|
int major, minor;
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
|
|
||||||
ptr = locals->user_agent_prefix + snprintf(locals->user_agent_prefix, sizeof(locals->user_agent_prefix), "RetroArch/%s", PACKAGE_VERSION);
|
|
||||||
|
|
||||||
if (frontend && frontend->get_os)
|
if (frontend && frontend->get_os)
|
||||||
{
|
{
|
||||||
frontend->get_os(tmp, sizeof(tmp), &major, &minor);
|
frontend->get_os(tmp, sizeof(tmp), &major, &minor);
|
||||||
ptr += sprintf(ptr, " (%s %d.%d)", tmp, major, minor);
|
snprintf(locals->user_agent_prefix, sizeof(locals->user_agent_prefix),
|
||||||
(void)ptr;
|
"RetroArch/%s (%s %d.%d)", PACKAGE_VERSION, tmp, major, minor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(locals->user_agent_prefix, sizeof(locals->user_agent_prefix),
|
||||||
|
"RetroArch/%s", PACKAGE_VERSION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = buffer + snprintf(buffer, len, "%s", locals->user_agent_prefix);
|
/* append the non-changing portion */
|
||||||
|
ptr = buffer + strlcpy(buffer, locals->user_agent_prefix, len);
|
||||||
|
|
||||||
|
/* if a core is loaded, append its information */
|
||||||
if (system && !string_is_empty(system->library_name))
|
if (system && !string_is_empty(system->library_name))
|
||||||
{
|
{
|
||||||
|
char* stop = buffer + len - 1;
|
||||||
const char* path = path_get(RARCH_PATH_CORE);
|
const char* path = path_get(RARCH_PATH_CORE);
|
||||||
|
*ptr++ = ' ';
|
||||||
|
|
||||||
if (!string_is_empty(path))
|
if (!string_is_empty(path))
|
||||||
{
|
{
|
||||||
sprintf(ptr, " %s", path_basename(path));
|
append_no_spaces(ptr, stop, path_basename(path));
|
||||||
path_remove_extension(ptr);
|
path_remove_extension(ptr);
|
||||||
ptr += strlen(ptr);
|
ptr += strlen(ptr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*ptr++ = ' ';
|
ptr += append_no_spaces(ptr, stop, system->library_name);
|
||||||
|
|
||||||
scan = system->library_name;
|
|
||||||
while (*scan)
|
|
||||||
{
|
|
||||||
if (*scan == ' ')
|
|
||||||
{
|
|
||||||
*ptr++ = '_';
|
|
||||||
++scan;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*ptr++ = *scan++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (system->library_version)
|
if (system->library_version)
|
||||||
{
|
{
|
||||||
*ptr++ = '/';
|
*ptr++ = '/';
|
||||||
|
ptr += append_no_spaces(ptr, stop, system->library_version);
|
||||||
scan = system->library_version;
|
|
||||||
while (*scan)
|
|
||||||
{
|
|
||||||
if (*scan == ' ')
|
|
||||||
{
|
|
||||||
*ptr++ = '_';
|
|
||||||
++scan;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*ptr++ = *scan++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
deps/rcheevos/src/rurl/url.c
vendored
2
deps/rcheevos/src/rurl/url.c
vendored
@ -298,7 +298,7 @@ static int rc_url_append_unum(char* buffer, size_t buffer_size, size_t* buffer_o
|
|||||||
int written = rc_url_append_param_equals(buffer, buffer_size, *buffer_offset, param);
|
int written = rc_url_append_param_equals(buffer, buffer_size, *buffer_offset, param);
|
||||||
if (written > 0) {
|
if (written > 0) {
|
||||||
char num[16];
|
char num[16];
|
||||||
int chars = sprintf(num, "%u", value);
|
int chars = snprintf(num, sizeof(num), "%u", value);
|
||||||
|
|
||||||
if (chars + written < (int)buffer_size)
|
if (chars + written < (int)buffer_size)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user