Skip to content

Commit 5d9599e

Browse files
committed
Replace deprecated sprintf with snprintf
This replaces unsafe sprintf with snprintf to address security concerns and compiler deprecation warning on macOS. The change explicitly specifies buffer size to prevent potential buffer overflows while maintaining the same functionality.
1 parent f29a741 commit 5d9599e

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)