On OpenBSD 7.8, gl_cv_func_printf_enomem is defined to "no". This case
wasn't documented previously, but we can see the cause using this diff:

    diff --git a/m4/printf.m4 b/m4/printf.m4
    index 0de493b690..1221de172f 100644
    --- a/m4/printf.m4
    +++ b/m4/printf.m4
    @@ -1547,6 +1547,8 @@ AC_DEFUN([gl_PRINTF_ENOMEM]
         return 77;
     #endif
       ret = printf ("%.5000000f", 1.0);
    +  printf ("%s\n", strerror (errno));
    +  printf ("%d\n", ret);
       return !(ret == 5000002 || (ret < 0 && errno == ENOMEM));
     }
               ]])])

It reveals that printf returns zero despite errno being set to ENOMEM
and nothing being printed.

Our autoconf tests already caught this, but here is a patch documenting
it.

Collin

>From f1aae65e7aaaf88ae77766ac2be140ae6fc017c9 Mon Sep 17 00:00:00 2001
Message-ID: <f1aae65e7aaaf88ae77766ac2be140ae6fc017c9.1768855736.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Mon, 19 Jan 2026 12:45:07 -0800
Subject: [PATCH] doc: mention an OpenBSD printf bug.

* doc/posix-functions/printf.texi: Mention that OpenBSD does not return
a negative number after running out of memory.
---
 ChangeLog                       | 6 ++++++
 doc/posix-functions/printf.texi | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index b96ea8fcf3..eac539ae34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-01-19  Collin Funk  <[email protected]>
+
+	doc: mention an OpenBSD printf bug.
+	* doc/posix-functions/printf.texi: Mention that OpenBSD does not return
+	a negative number after running out of memory.
+
 2026-01-19  Paul Eggert  <[email protected]>
 
 	xalloc: tweak for GCC 4.6, possible inlining bugs
diff --git a/doc/posix-functions/printf.texi b/doc/posix-functions/printf.texi
index 8b33702a83..a67e3c5e8f 100644
--- a/doc/posix-functions/printf.texi
+++ b/doc/posix-functions/printf.texi
@@ -111,6 +111,10 @@ @node printf
 @item
 This function can crash in out-of-memory conditions on some platforms:
 FreeBSD 14.0, NetBSD 5.0.
+@item
+This function returns zero instead of a negative number after running
+out of memory:
+OpenBSD 7.8.
 @end itemize
 
 Portability problems fixed by Gnulib module @code{printf-gnu}:
-- 
2.52.0

Reply via email to