Index: flang/unittests/Decimal/quick-sanity-test.cpp =================================================================== --- flang/unittests/Decimal/quick-sanity-test.cpp +++ flang/unittests/Decimal/quick-sanity-test.cpp @@ -53,7 +53,8 @@ ++expo; } if (q >= buffer && q < buffer + sizeof buffer) { - std::snprintf(q + result.length, sizeof buffer, "e%d", expo); + std::snprintf(q + result.length, + buffer + sizeof buffer - (q + result.length), "e%d", expo); } const char *p{q}; auto rflags{ConvertDecimalToFloat(&p, &y, RoundNearest)}; Index: flang/unittests/Decimal/thorough-test.cpp =================================================================== --- flang/unittests/Decimal/thorough-test.cpp +++ flang/unittests/Decimal/thorough-test.cpp @@ -51,7 +51,8 @@ if (*q == '-' || *q == '+') { ++expo; } - std::snprintf(q + result.length, sizeof buffer, "e%d", expo); + std::snprintf(q + result.length, + buffer + sizeof buffer - (q + result.length), "e%d", expo); } const char *p{q}; auto rflags{ConvertDecimalToFloat(&p, &y, RoundNearest)};