Skip to content

Commit 5c88190

Browse files
authored
flambda-backend: Improve error handling in caml_alloc_sprintf (upstream PR 12489) (#2117)
Improve error handling in caml_alloc_sprintf (upstream 12489)
1 parent 781bb48 commit 5c88190

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

runtime/str.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,9 @@ CAMLexport value caml_alloc_sprintf(const char * format, ...)
411411
excluding the terminating '\0'. */
412412
n = vsnprintf(buf, sizeof(buf), format, args);
413413
va_end(args);
414-
if (n < sizeof(buf)) {
414+
if (n < 0) {
415+
caml_raise_out_of_memory();
416+
} else if (n < sizeof(buf)) {
415417
/* All output characters were written to buf, including the
416418
terminating '\0'. Allocate a Caml string with length "n"
417419
as computed by vsnprintf, and copy the output of vsnprintf into it. */

0 commit comments

Comments
 (0)