Skip to content

Commit f521ca5

Browse files
committed
Replace deprecated sprintf with snprintf
This change replaces the unsafe use of sprintf with snprintf to address security concerns and resolve a compiler deprecation warning on macOS. By explicitly specifying the buffer size, it prevents potential buffer overflows while preserving the same functionality.
1 parent f29a741 commit f521ca5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ static bool parse_args(int argc, char **args)
184184
strlen(prog_basename) + 5 + 1);
185185
assert(prof_out_file);
186186

187-
sprintf(prof_out_file, "%s/%s%s.prof", cwd_path, rel_path,
188-
prog_basename);
187+
snprintf(prof_out_file,
188+
strlen(cwd_path) + 1 + strlen(rel_path) +
189+
strlen(prog_basename) + 5 + 1,
190+
"%s/%s%s.prof", cwd_path, rel_path, prog_basename);
189191
}
190192
return true;
191193
}

0 commit comments

Comments
 (0)