Use strldup where possible, avoid strcpy_literal

This commit is contained in:
LibretroAdmin 2025-01-15 16:36:49 +01:00
parent 9da7af46c3
commit b2072dd3be
3 changed files with 20 additions and 57 deletions

View File

@ -328,7 +328,7 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
* but I have not seen any real examples of them. */ * but I have not seen any real examples of them. */
info->system_id = MEDIA_CD_SYSTEM_MEGA_CD; info->system_id = MEDIA_CD_SYSTEM_MEGA_CD;
strcpy_literal(info->system, "Sega CD / Mega CD"); strlcpy(info->system, "Sega CD / Mega CD", sizeof(info->system));
title_pos = buf + offset + 0x150; title_pos = buf + offset + 0x150;
@ -338,12 +338,7 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
media_zero_trailing_spaces(info->title, sizeof(info->title)); media_zero_trailing_spaces(info->title, sizeof(info->title));
} }
else else
{ strlcpy(info->title, "N/A", sizeof(info->title));
info->title[0] = 'N';
info->title[1] = '/';
info->title[2] = 'A';
info->title[3] = '\0';
}
serial_pos = buf + offset + 0x183; serial_pos = buf + offset + 0x183;
@ -370,7 +365,7 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
info->system_id = MEDIA_CD_SYSTEM_SATURN; info->system_id = MEDIA_CD_SYSTEM_SATURN;
strcpy_literal(info->system, "Sega Saturn"); strlcpy(info->system, "Sega Saturn", sizeof(info->system));
title_pos = buf + offset + 0x60; title_pos = buf + offset + 0x60;
@ -380,12 +375,7 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
media_zero_trailing_spaces(info->title, sizeof(info->title)); media_zero_trailing_spaces(info->title, sizeof(info->title));
} }
else else
{ strlcpy(info->title, "N/A", sizeof(info->title));
info->title [0] = 'N';
info->title [1] = '/';
info->title [2] = 'A';
info->title [3] = '\0';
}
serial_pos = buf + offset + 0x20; serial_pos = buf + offset + 0x20;
@ -441,7 +431,7 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
info->system_id = MEDIA_CD_SYSTEM_DREAMCAST; info->system_id = MEDIA_CD_SYSTEM_DREAMCAST;
strcpy_literal(info->system, "Sega Dreamcast"); strlcpy(info->system, "Sega Dreamcast", sizeof(info->system));
title_pos = buf + offset + 0x80; title_pos = buf + offset + 0x80;
@ -451,12 +441,7 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
media_zero_trailing_spaces(info->title, sizeof(info->title)); media_zero_trailing_spaces(info->title, sizeof(info->title));
} }
else else
{ strlcpy(info->title, "N/A", sizeof(info->title));
info->title [0] = 'N';
info->title [1] = '/';
info->title [2] = 'A';
info->title [3] = '\0';
}
serial_pos = buf + offset + 0x40; serial_pos = buf + offset + 0x40;
@ -510,7 +495,7 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
info->system_id = MEDIA_CD_SYSTEM_PSX; info->system_id = MEDIA_CD_SYSTEM_PSX;
strcpy_literal(info->system, "Sony PlayStation"); strlcpy(info->system, "Sony PlayStation", sizeof(info->system));
title_pos = buf + offset + (16 * sector_size) + 40; title_pos = buf + offset + (16 * sector_size) + 40;
@ -520,22 +505,17 @@ bool media_detect_cd_info(const char *path, uint64_t pregap_bytes, media_detect_
media_zero_trailing_spaces(info->title, sizeof(info->title)); media_zero_trailing_spaces(info->title, sizeof(info->title));
} }
else else
{ strlcpy(info->title, "N/A", sizeof(info->title));
info->title [0] = 'N';
info->title [1] = '/';
info->title [2] = 'A';
info->title [3] = '\0';
}
} }
else if (!memcmp(buf + offset, "\x01\x5a\x5a\x5a\x5a\x5a\x01\x00\x00\x00\x00\x00", 12)) else if (!memcmp(buf + offset, "\x01\x5a\x5a\x5a\x5a\x5a\x01\x00\x00\x00\x00\x00", 12))
{ {
info->system_id = MEDIA_CD_SYSTEM_3DO; info->system_id = MEDIA_CD_SYSTEM_3DO;
strcpy_literal(info->system, "3DO"); strlcpy(info->system, "3DO", sizeof(info->system));
} }
else if (!memcmp(buf + offset + 0x950, "PC Engine CD-ROM SYSTEM", 23)) else if (!memcmp(buf + offset + 0x950, "PC Engine CD-ROM SYSTEM", 23))
{ {
info->system_id = MEDIA_CD_SYSTEM_PC_ENGINE_CD; info->system_id = MEDIA_CD_SYSTEM_PC_ENGINE_CD;
strcpy_literal(info->system, "TurboGrafx-CD / PC-Engine CD"); strlcpy(info->system, "TurboGrafx-CD / PC-Engine CD", sizeof(info->system));
} }
free(buf); free(buf);

View File

@ -272,15 +272,13 @@ static void query_raise_unknown_function(
ssize_t where, const char *name, ssize_t where, const char *name,
ssize_t len, const char **error) ssize_t len, const char **error)
{ {
int n = snprintf(s, _len, int __len = snprintf(s, _len,
"%" PRIu64 "::Unknown function '", "%" PRIu64 "::Unknown function '",
(uint64_t)where (uint64_t)where
); );
if (len < ((ssize_t)_len - __len - 3))
if (len < ((ssize_t)_len - n - 3)) strncpy(s + __len, name, len);
strncpy(s + n, name, len); strcpy_literal(s + __len + len, "'");
strcpy_literal(s + n + len, "'");
*error = s; *error = s;
} }
@ -671,8 +669,7 @@ static struct buffer query_parse_method_call(
{ {
if (argi >= QUERY_MAX_ARGS) if (argi >= QUERY_MAX_ARGS)
{ {
strcpy_literal(s, strlcpy(s, "Too many arguments in function call.", len);
"Too many arguments in function call.");
*error = s; *error = s;
goto clean; goto clean;
} }
@ -797,8 +794,7 @@ static struct buffer query_parse_table(
{ {
if (argi >= QUERY_MAX_ARGS) if (argi >= QUERY_MAX_ARGS)
{ {
strcpy_literal(s, strlcpy(s, "Too many arguments in function call.", len);
"Too many arguments in function call.");
*error = s; *error = s;
goto clean; goto clean;
} }
@ -846,8 +842,7 @@ static struct buffer query_parse_table(
if (argi >= QUERY_MAX_ARGS) if (argi >= QUERY_MAX_ARGS)
{ {
strcpy_literal(s, strlcpy(s, "Too many arguments in function call.", len);
"Too many arguments in function call.");
*error = s; *error = s;
goto clean; goto clean;
} }

View File

@ -150,11 +150,7 @@ static void strcat_alloc(char **dst, const char *s)
{ {
size_t __len = strlen(s); size_t __len = strlen(s);
if (__len != 0) if (__len != 0)
{ src = strldup(s, __len);
char *_dst= (char*)malloc(__len + 1);
strcpy_literal(_dst, s);
src = _dst;
}
else else
src = NULL; src = NULL;
} }
@ -243,11 +239,7 @@ static char *get_tmpdir_alloc(const char *override_dir)
{ {
size_t _len = strlen(src); size_t _len = strlen(src);
if (_len != 0) if (_len != 0)
{ path = strldup(src, _len);
char *dst = (char*)malloc(_len + 1);
strcpy_literal(dst, src);
path = dst;
}
} }
else else
path = (char*)calloc(1,1); path = (char*)calloc(1,1);
@ -272,11 +264,7 @@ static bool write_file_with_random_name(char **temp_dll_path,
{ {
size_t _len = strlen(src); size_t _len = strlen(src);
if (_len != 0) if (_len != 0)
{ ext = strldup(src, _len);
char *dst = (char*)malloc(_len + 1);
strcpy_literal(dst, src);
ext = dst;
}
} }
else else
ext = (char*)calloc(1,1); ext = (char*)calloc(1,1);