Skip to content

Commit

Permalink
flambda-backend: Improve error handling in caml_alloc_sprintf (upstre…
Browse files Browse the repository at this point in the history
…am PR 12489) (#2117)

Improve error handling in caml_alloc_sprintf (upstream 12489)
  • Loading branch information
stedolan authored Dec 4, 2023
1 parent 781bb48 commit 5c88190
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion runtime/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ CAMLexport value caml_alloc_sprintf(const char * format, ...)
excluding the terminating '\0'. */
n = vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
if (n < sizeof(buf)) {
if (n < 0) {
caml_raise_out_of_memory();
} else if (n < sizeof(buf)) {
/* All output characters were written to buf, including the
terminating '\0'. Allocate a Caml string with length "n"
as computed by vsnprintf, and copy the output of vsnprintf into it. */
Expand Down

0 comments on commit 5c88190

Please sign in to comment.