Skip to content

Commit 5936908

Browse files
committed
clang-tools: Fix sprintf is deprecated warnings
1 parent f334db9 commit 5936908

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

clang/tools/c-index-test/c-index-test.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static int parse_remapped_files_with_try(int try_idx,
374374
if (ret)
375375
return ret;
376376

377-
sprintf(opt_name, "-remap-file-%d=", try_idx);
377+
snprintf(opt_name, sizeof(opt_name), "-remap-file-%d=", try_idx);
378378
ret = parse_remapped_files_with_opt(opt_name, argc, argv, start_arg,
379379
&unsaved_files_try_idx, &num_unsaved_files_try_idx);
380380
if (ret)
@@ -1182,8 +1182,9 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
11821182
CXString Spelling = clang_getCursorSpelling(Cursor);
11831183
const char *CName = clang_getCString(Name);
11841184
const char *CSpelling = clang_getCString(Spelling);
1185-
char *DefaultSetter = malloc(strlen(CSpelling) + 5);
1186-
sprintf(DefaultSetter, "set%s:", CSpelling);
1185+
size_t Len = strlen(CSpelling) + 5;
1186+
char *DefaultSetter = malloc(Len);
1187+
snprintf(DefaultSetter, Len, "set%s:", CSpelling);
11871188
DefaultSetter[3] &= ~(1 << 5); /* Make uppercase */
11881189
if (CName && strcmp(CName, DefaultSetter)) {
11891190
printf(" (setter=%s)", CName);
@@ -3526,19 +3527,19 @@ static CXIdxClientContainer makeClientContainer(CXClientData *client_data,
35263527
char *newStr;
35273528
CXIdxClientFile file;
35283529
unsigned line, column;
3529-
3530+
size_t len;
3531+
35303532
name = info->name;
35313533
if (!name)
35323534
name = "<anon-tag>";
35333535

35343536
clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
35353537

3536-
node =
3537-
(IndexDataStringList *)malloc(sizeof(IndexDataStringList) + strlen(name) +
3538-
digitCount(line) + digitCount(column) + 2);
3538+
len = strlen(name) + digitCount(line) + digitCount(column) + 2;
3539+
node = (IndexDataStringList *)malloc(sizeof(IndexDataStringList) + len);
35393540
assert(node);
35403541
newStr = node->data;
3541-
sprintf(newStr, "%s:%d:%d", name, line, column);
3542+
snprintf(newStr, len, "%s:%d:%d", name, line, column);
35423543

35433544
/* Remember string so it can be freed later. */
35443545
index_data = (IndexData *)client_data;

0 commit comments

Comments
 (0)