Skip to content

Improve error handling in caml_alloc_sprintf (upstream PR 12489) #2117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ocaml/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