aboutsummaryrefslogtreecommitdiff
path: root/clang/tools/c-index-test/c-index-test.c
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2025-03-04 09:53:31 +0700
committerGitHub <noreply@github.com>2025-03-04 09:53:31 +0700
commitce1a18e2c714f39fe72cd46aa04faed29ad23cb6 (patch)
treebcb91e4f1c1a63d2165f30b42b02f6e861c37875 /clang/tools/c-index-test/c-index-test.c
parent956e56fa6d3d62e1ef1a27bdc9f6be3c0544b9c7 (diff)
downloadllvm-ce1a18e2c714f39fe72cd46aa04faed29ad23cb6.zip
llvm-ce1a18e2c714f39fe72cd46aa04faed29ad23cb6.tar.gz
llvm-ce1a18e2c714f39fe72cd46aa04faed29ad23cb6.tar.bz2
clang-tools: Fix sprintf is deprecated warnings (#120517)
Diffstat (limited to 'clang/tools/c-index-test/c-index-test.c')
-rw-r--r--clang/tools/c-index-test/c-index-test.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 0e7de8b..942500f 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -376,7 +376,7 @@ static int parse_remapped_files_with_try(int try_idx,
if (ret)
return ret;
- sprintf(opt_name, "-remap-file-%d=", try_idx);
+ snprintf(opt_name, sizeof(opt_name), "-remap-file-%d=", try_idx);
ret = parse_remapped_files_with_opt(opt_name, argc, argv, start_arg,
&unsaved_files_try_idx, &num_unsaved_files_try_idx);
if (ret)
@@ -1184,8 +1184,9 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
CXString Spelling = clang_getCursorSpelling(Cursor);
const char *CName = clang_getCString(Name);
const char *CSpelling = clang_getCString(Spelling);
- char *DefaultSetter = malloc(strlen(CSpelling) + 5);
- sprintf(DefaultSetter, "set%s:", CSpelling);
+ size_t Len = strlen(CSpelling) + 5;
+ char *DefaultSetter = malloc(Len);
+ snprintf(DefaultSetter, Len, "set%s:", CSpelling);
DefaultSetter[3] &= ~(1 << 5); /* Make uppercase */
if (CName && strcmp(CName, DefaultSetter)) {
printf(" (setter=%s)", CName);
@@ -3545,19 +3546,20 @@ static CXIdxClientContainer makeClientContainer(CXClientData *client_data,
char *newStr;
CXIdxClientFile file;
unsigned line, column;
-
+ size_t len;
+
name = info->name;
if (!name)
name = "<anon-tag>";
clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
- node =
- (IndexDataStringList *)malloc(sizeof(IndexDataStringList) + strlen(name) +
- digitCount(line) + digitCount(column) + 2);
+ len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
+ digitCount(column) + 2;
+ node = (IndexDataStringList *)malloc(len);
assert(node);
newStr = node->data;
- sprintf(newStr, "%s:%d:%d", name, line, column);
+ snprintf(newStr, len, "%s:%d:%d", name, line, column);
/* Remember string so it can be freed later. */
index_data = (IndexData *)client_data;