AK: Prefer snprintf over sprintf

This commit is contained in:
Ben Wiederhake 2020-08-16 15:47:33 +02:00 committed by Andreas Kling
parent b6afe1f0ce
commit 04f494fc44
Notes: sideshowbarker 2024-07-19 03:17:06 +09:00
2 changed files with 13 additions and 13 deletions

View File

@ -60,49 +60,49 @@ const LogStream& operator<<(const LogStream& stream, const StringView& value)
const LogStream& operator<<(const LogStream& stream, int value) const LogStream& operator<<(const LogStream& stream, int value)
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "%d", value); snprintf(buffer, sizeof(buffer), "%d", value);
return stream << buffer; return stream << buffer;
} }
const LogStream& operator<<(const LogStream& stream, long value) const LogStream& operator<<(const LogStream& stream, long value)
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "%ld", value); snprintf(buffer, sizeof(buffer), "%ld", value);
return stream << buffer; return stream << buffer;
} }
const LogStream& operator<<(const LogStream& stream, long long value) const LogStream& operator<<(const LogStream& stream, long long value)
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "%lld", value); snprintf(buffer, sizeof(buffer), "%lld", value);
return stream << buffer; return stream << buffer;
} }
const LogStream& operator<<(const LogStream& stream, unsigned value) const LogStream& operator<<(const LogStream& stream, unsigned value)
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "%u", value); snprintf(buffer, sizeof(buffer), "%u", value);
return stream << buffer; return stream << buffer;
} }
const LogStream& operator<<(const LogStream& stream, unsigned long long value) const LogStream& operator<<(const LogStream& stream, unsigned long long value)
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "%llu", value); snprintf(buffer, sizeof(buffer), "%llu", value);
return stream << buffer; return stream << buffer;
} }
const LogStream& operator<<(const LogStream& stream, unsigned long value) const LogStream& operator<<(const LogStream& stream, unsigned long value)
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "%lu", value); snprintf(buffer, sizeof(buffer), "%lu", value);
return stream << buffer; return stream << buffer;
} }
const LogStream& operator<<(const LogStream& stream, const void* value) const LogStream& operator<<(const LogStream& stream, const void* value)
{ {
char buffer[32]; char buffer[32];
sprintf(buffer, "%p", value); snprintf(buffer, sizeof(buffer), "%p", value);
return stream << buffer; return stream << buffer;
} }

View File

@ -210,7 +210,7 @@ String String::number(unsigned long long value)
{ {
int size; int size;
char buffer[32]; char buffer[32];
size = sprintf(buffer, "%llu", value); size = snprintf(buffer, sizeof(buffer), "%llu", value);
return String(buffer, size); return String(buffer, size);
} }
@ -218,35 +218,35 @@ String String::number(unsigned long value)
{ {
int size; int size;
char buffer[32]; char buffer[32];
size = sprintf(buffer, "%lu", value); size = snprintf(buffer, sizeof(buffer), "%lu", value);
return String(buffer, size); return String(buffer, size);
} }
String String::number(unsigned value) String String::number(unsigned value)
{ {
char buffer[32]; char buffer[32];
int size = sprintf(buffer, "%u", value); int size = snprintf(buffer, sizeof(buffer), "%u", value);
return String(buffer, size); return String(buffer, size);
} }
String String::number(long long value) String String::number(long long value)
{ {
char buffer[32]; char buffer[32];
int size = sprintf(buffer, "%lld", value); int size = snprintf(buffer, sizeof(buffer), "%lld", value);
return String(buffer, size); return String(buffer, size);
} }
String String::number(long value) String String::number(long value)
{ {
char buffer[32]; char buffer[32];
int size = sprintf(buffer, "%ld", value); int size = snprintf(buffer, sizeof(buffer), "%ld", value);
return String(buffer, size); return String(buffer, size);
} }
String String::number(int value) String String::number(int value)
{ {
char buffer[32]; char buffer[32];
int size = sprintf(buffer, "%d", value); int size = snprintf(buffer, sizeof(buffer), "%d", value);
return String(buffer, size); return String(buffer, size);
} }