mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Use sizeof for buffer lengths in snprintf
Rather than duplicating the constant value, use the `sizeof` operator to have the value propogate from the static buffer allocation. Any standards conforming implementation of `snprintf` will null-terminate the output unless the buffer is NULL (a zero-sized buffer is passed to the call). On Windows, where this is not the case, the function is named `_snprintf` which ensures that we do not accidentally end up with the incorrect behaviour.
This commit is contained in:
@@ -37,13 +37,13 @@ static void unreachable(const char *Message) {
|
||||
|
||||
DemanglerPrinter &DemanglerPrinter::operator<<(unsigned long long n) & {
|
||||
char buffer[32];
|
||||
snprintf(buffer, 32, "%llu", n);
|
||||
snprintf(buffer, sizeof(buffer), "%llu", n);
|
||||
Stream.append(buffer);
|
||||
return *this;
|
||||
}
|
||||
DemanglerPrinter &DemanglerPrinter::operator<<(long long n) & {
|
||||
char buffer[32];
|
||||
snprintf(buffer, 32, "%lld",n);
|
||||
snprintf(buffer, sizeof(buffer), "%lld",n);
|
||||
Stream.append(buffer);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user