diff --git a/src/lib/pcre/UniqueRegex.cxx b/src/lib/pcre/UniqueRegex.cxx
index deaae0898..48e4ceb3b 100644
--- a/src/lib/pcre/UniqueRegex.cxx
+++ b/src/lib/pcre/UniqueRegex.cxx
@@ -4,8 +4,7 @@
 
 #include "UniqueRegex.hxx"
 #include "Error.hxx"
-
-#include <stdio.h>
+#include "lib/fmt/ToBuffer.hxx"
 
 void
 UniqueRegex::Compile(const char *pattern, bool anchored, bool capture,
@@ -28,9 +27,8 @@ UniqueRegex::Compile(const char *pattern, bool anchored, bool capture,
 			     &error_number, &error_offset,
 			     nullptr);
 	if (re == nullptr) {
-		char msg[256];
-		snprintf(msg, sizeof(msg), "Error in regex at offset %zu",
-			 error_offset);
+		const auto msg = FmtBuffer<256>("Error in regex at offset {}",
+						error_offset);
 		throw Pcre::MakeError(error_number, msg);
 	}
 
diff --git a/src/lib/pcre/meson.build b/src/lib/pcre/meson.build
index 074c4dcad..3839ff6b9 100644
--- a/src/lib/pcre/meson.build
+++ b/src/lib/pcre/meson.build
@@ -16,6 +16,7 @@ pcre = static_library(
   include_directories: inc,
   dependencies: [
     pcre_dep,
+    fmt_dep,
   ],
 )