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:
Saleem Abdulrasool
2016-06-15 17:41:16 -07:00
parent e9fff22e53
commit c553628964
3 changed files with 4 additions and 5 deletions

View File

@@ -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;
}