diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2020-08-16 15:47:33 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-22 20:55:10 +0200 |
commit | 04f494fc44ec07225dd8168d48c77d9e04e520ba (patch) | |
tree | 155de36b318a0effa956aedc9365f08e3dd7ada4 | |
parent | b6afe1f0cecd1025afcc99771acc9580b4079691 (diff) | |
download | serenity-04f494fc44ec07225dd8168d48c77d9e04e520ba.zip |
AK: Prefer snprintf over sprintf
-rw-r--r-- | AK/LogStream.cpp | 14 | ||||
-rw-r--r-- | AK/String.cpp | 12 |
2 files changed, 13 insertions, 13 deletions
diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp index 52185d1530..9037f45fb3 100644 --- a/AK/LogStream.cpp +++ b/AK/LogStream.cpp @@ -60,49 +60,49 @@ const LogStream& operator<<(const LogStream& stream, const StringView& value) const LogStream& operator<<(const LogStream& stream, int value) { char buffer[32]; - sprintf(buffer, "%d", value); + snprintf(buffer, sizeof(buffer), "%d", value); return stream << buffer; } const LogStream& operator<<(const LogStream& stream, long value) { char buffer[32]; - sprintf(buffer, "%ld", value); + snprintf(buffer, sizeof(buffer), "%ld", value); return stream << buffer; } const LogStream& operator<<(const LogStream& stream, long long value) { char buffer[32]; - sprintf(buffer, "%lld", value); + snprintf(buffer, sizeof(buffer), "%lld", value); return stream << buffer; } const LogStream& operator<<(const LogStream& stream, unsigned value) { char buffer[32]; - sprintf(buffer, "%u", value); + snprintf(buffer, sizeof(buffer), "%u", value); return stream << buffer; } const LogStream& operator<<(const LogStream& stream, unsigned long long value) { char buffer[32]; - sprintf(buffer, "%llu", value); + snprintf(buffer, sizeof(buffer), "%llu", value); return stream << buffer; } const LogStream& operator<<(const LogStream& stream, unsigned long value) { char buffer[32]; - sprintf(buffer, "%lu", value); + snprintf(buffer, sizeof(buffer), "%lu", value); return stream << buffer; } const LogStream& operator<<(const LogStream& stream, const void* value) { char buffer[32]; - sprintf(buffer, "%p", value); + snprintf(buffer, sizeof(buffer), "%p", value); return stream << buffer; } diff --git a/AK/String.cpp b/AK/String.cpp index 2b4282657e..0be8c0fd99 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -210,7 +210,7 @@ String String::number(unsigned long long value) { int size; char buffer[32]; - size = sprintf(buffer, "%llu", value); + size = snprintf(buffer, sizeof(buffer), "%llu", value); return String(buffer, size); } @@ -218,35 +218,35 @@ String String::number(unsigned long value) { int size; char buffer[32]; - size = sprintf(buffer, "%lu", value); + size = snprintf(buffer, sizeof(buffer), "%lu", value); return String(buffer, size); } String String::number(unsigned value) { char buffer[32]; - int size = sprintf(buffer, "%u", value); + int size = snprintf(buffer, sizeof(buffer), "%u", value); return String(buffer, size); } String String::number(long long value) { char buffer[32]; - int size = sprintf(buffer, "%lld", value); + int size = snprintf(buffer, sizeof(buffer), "%lld", value); return String(buffer, size); } String String::number(long value) { char buffer[32]; - int size = sprintf(buffer, "%ld", value); + int size = snprintf(buffer, sizeof(buffer), "%ld", value); return String(buffer, size); } String String::number(int value) { char buffer[32]; - int size = sprintf(buffer, "%d", value); + int size = snprintf(buffer, sizeof(buffer), "%d", value); return String(buffer, size); } |