mirror of https://github.com/OpenTTD/OpenTTD
Codechange: replace last strncmp uses
parent
31754a0afd
commit
26a4da9b01
|
@ -460,6 +460,7 @@ bool TarScanner::AddFile(const std::string &filename, size_t, [[maybe_unused]] c
|
|||
|
||||
char unused[12];
|
||||
};
|
||||
static_assert(sizeof(TarHeader) == 512);
|
||||
|
||||
/* Check if we already seen this file */
|
||||
TarList::iterator it = _tar_list[this->subdir].find(filename);
|
||||
|
@ -481,19 +482,16 @@ bool TarScanner::AddFile(const std::string &filename, size_t, [[maybe_unused]] c
|
|||
TarHeader th;
|
||||
size_t num = 0, pos = 0;
|
||||
|
||||
/* Make a char of 512 empty bytes */
|
||||
char empty[512];
|
||||
memset(&empty[0], 0, sizeof(empty));
|
||||
|
||||
for (;;) { // Note: feof() always returns 'false' after 'fseek()'. Cool, isn't it?
|
||||
size_t num_bytes_read = fread(&th, 1, 512, f);
|
||||
if (num_bytes_read != 512) break;
|
||||
size_t num_bytes_read = fread(&th, 1, sizeof(TarHeader), f);
|
||||
if (num_bytes_read != sizeof(TarHeader)) break;
|
||||
pos += num_bytes_read;
|
||||
|
||||
/* Check if we have the new tar-format (ustar) or the old one (a lot of zeros after 'link' field) */
|
||||
if (strncmp(th.magic, "ustar", 5) != 0 && memcmp(&th.magic, &empty[0], 512 - offsetof(TarHeader, magic)) != 0) {
|
||||
auto last_of_th = &th.unused[std::size(th.unused)];
|
||||
if (std::string_view{th.magic, 5} != "ustar" && std::any_of(th.magic, last_of_th, [](auto c) { return c != 0; })) {
|
||||
/* If we have only zeros in the block, it can be an end-of-file indicator */
|
||||
if (memcmp(&th, &empty[0], 512) == 0) continue;
|
||||
if (std::all_of(th.name, last_of_th, [](auto c) { return c == 0; })) continue;
|
||||
|
||||
Debug(misc, 0, "The file '{}' isn't a valid tar-file", filename);
|
||||
return false;
|
||||
|
|
|
@ -73,9 +73,9 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
|
|||
if (((symbolic_traits & kCTFontMonoSpaceTrait) == kCTFontMonoSpaceTrait) != callback->Monospace()) continue;
|
||||
|
||||
/* Get font name. */
|
||||
char name[128];
|
||||
char buffer[128];
|
||||
CFAutoRelease<CFStringRef> font_name((CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontDisplayNameAttribute));
|
||||
CFStringGetCString(font_name.get(), name, lengthof(name), kCFStringEncodingUTF8);
|
||||
CFStringGetCString(font_name.get(), buffer, std::size(buffer), kCFStringEncodingUTF8);
|
||||
|
||||
/* Serif fonts usually look worse on-screen with only small
|
||||
* font sizes. As such, we try for a sans-serif font first.
|
||||
|
@ -84,7 +84,8 @@ bool SetFallbackFont(FontCacheSettings *settings, const std::string &language_is
|
|||
|
||||
/* There are some special fonts starting with an '.' and the last
|
||||
* resort font that aren't usable. Skip them. */
|
||||
if (name[0] == '.' || strncmp(name, "LastResort", 10) == 0) continue;
|
||||
std::string_view name{buffer};
|
||||
if (name.starts_with(".") || name.starts_with("LastResort")) continue;
|
||||
|
||||
/* Save result. */
|
||||
callback->SetFontNames(settings, name);
|
||||
|
|
|
@ -21,33 +21,33 @@
|
|||
#define calloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define realloc SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
/* Use std::string instead. */
|
||||
/* Use std::string/std::string_view instead. */
|
||||
#define strdup SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define strndup SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
/* Use strecpy instead. */
|
||||
#define strcpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define strncpy SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
/* Use std::string concatenation/fmt::format instead. */
|
||||
#define strcat SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define strncat SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
/* Use fmt::format instead. */
|
||||
#define sprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define snprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
/* Use fmt::format instead. */
|
||||
#define vsprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define vsnprintf SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
#define strncmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define strcasecmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#ifdef stricmp
|
||||
#undef stricmp
|
||||
#endif
|
||||
#define stricmp SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
/* Use fgets instead. */
|
||||
#define gets SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
/* No clear replacement. */
|
||||
#define strtok SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
/* Use StringConsumer instead. */
|
||||
#define strtok SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define sscanf SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
#define from_string SAFEGUARD_DO_NOT_USE_THIS_METHOD
|
||||
|
||||
|
|
Loading…
Reference in New Issue