Use snprintf instead of deprecated sprintf

When compiling with -fsanitize=address on macOS, the deprecation of
sprintf is effective and prevents compiling yjit.c.

More details: https://openradar.appspot.com/FB11761475.
This commit is contained in:
Étienne Barrié 2025-08-01 11:15:21 +02:00 committed by Jean Boussier
parent 79d8a3159f
commit 4cfe5baf3d

5
yjit.c
View file

@ -622,8 +622,9 @@ rb_yjit_iseq_inspect(const rb_iseq_t *iseq)
const char *path = RSTRING_PTR(rb_iseq_path(iseq));
int lineno = iseq->body->location.code_location.beg_pos.lineno;
char *buf = ZALLOC_N(char, strlen(label) + strlen(path) + num_digits(lineno) + 3);
sprintf(buf, "%s@%s:%d", label, path, lineno);
const size_t size = strlen(label) + strlen(path) + num_digits(lineno) + 3;
char *buf = ZALLOC_N(char, size);
snprintf(buf, size, "%s@%s:%d", label, path, lineno);
return buf;
}