Skip to content

Commit bdce1b0

Browse files
committed
gnu hack
1 parent c9d24ea commit bdce1b0

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

lib/importproject.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,26 @@ static std::string safeFormat(const char *fmt, ...) {
466466
va_list args;
467467
va_start(args, fmt);
468468

469+
#if defined(__GNUC__)
470+
// GNU vsnprintf does not zero-pad %s. Handle the specific
471+
// "%0*s" form ourselves.
472+
if (std::strcmp(fmt, "-%0*s") == 0) {
473+
const int width = va_arg(args, int);
474+
const char *value = va_arg(args, const char *);
475+
476+
const std::string str = value ? value : "";
477+
const int padding = width - static_cast<int>(str.size());
478+
479+
std::string result = "-";
480+
if (padding > 0)
481+
result.append(static_cast<std::size_t>(padding), '0');
482+
result += str;
483+
484+
va_end(args);
485+
return result;
486+
}
487+
#endif
488+
469489
va_list argsCopy;
470490
va_copy(argsCopy, args);
471491
const int needed = std::vsnprintf(nullptr, 0, fmt, argsCopy);

0 commit comments

Comments
 (0)