Skip to content

Commit

Permalink
Merge pull request #4295 from PoeticPete/use-snprintf
Browse files Browse the repository at this point in the history
Use snprintf (instead of sprintf)
  • Loading branch information
micheleCTDEAdmin committed May 17, 2024
2 parents 5f1db37 + 6e19ccb commit a4cb495
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void print_numbering()
if (get_numbering())
{
line_number++;
sprintf(char_number, "%d ", line_number);
snprintf(char_number, sizeof(char_number), "%d ", line_number);
write_string(char_number);
}
}
Expand Down Expand Up @@ -539,7 +539,7 @@ void output_parsed(FILE *pfile, bool withOptions)
pc->GetBraceLevel(), pc->GetLevel(), pc->GetPpLevel());
// Print pc flags in groups of 4 hex characters
char flag_string[24];
sprintf(flag_string, "%16llx", static_cast<PcfFlags::int_t>(pc->GetFlags()));
snprintf(flag_string, sizeof(flag_string), "%16llx", static_cast<PcfFlags::int_t>(pc->GetFlags()));
fprintf(pfile, "[%.4s %.4s %.4s %.4s]", flag_string, flag_string + 4, flag_string + 8, flag_string + 12);
fprintf(pfile, "[%zu-%d]",
pc->GetNlCount(), pc->GetAfterTab());
Expand Down Expand Up @@ -1087,7 +1087,7 @@ void output_text(FILE *pfile)

if (first_text)
{
sprintf(tempText, "%s", Bsecond);
snprintf(tempText, sizeof(tempText), "%s", Bsecond);
add_text(tempText);
add_text(": ");
first_text = false;
Expand All @@ -1097,7 +1097,7 @@ void output_text(FILE *pfile)
{
add_text(", ");
}
sprintf(tempText, "%zu", Bfirst);
snprintf(tempText, sizeof(tempText), "%zu", Bfirst);
add_text(tempText);
} // for (size_t track = 0; track < pc->GetTrackingData()->size(); track++)

Expand Down
4 changes: 2 additions & 2 deletions src/space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3364,7 +3364,7 @@ static iarf_e do_space(Chunk *first, Chunk *second, int &min_sp)
|| it.second == second->GetType()))
{
char text[80];
sprintf(text, "REMOVE from no_space_table @ %zu.", number);
snprintf(text, sizeof(text), "REMOVE from no_space_table @ %zu.", number);
log_rule(text);
return(IARF_REMOVE);
}
Expand All @@ -3382,7 +3382,7 @@ static iarf_e do_space(Chunk *first, Chunk *second, int &min_sp)
&& it.second == second->GetType())
{
char text[80];
sprintf(text, "ADD from add_space_table @ %zu.", number);
snprintf(text, sizeof(text), "ADD from add_space_table @ %zu.", number);
log_rule(text);
return(IARF_ADD);
}
Expand Down
10 changes: 5 additions & 5 deletions src/unc_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,11 @@ void dump_out(unsigned int type)

if (cpd.dumped_file == nullptr)
{
sprintf(dumpFileName, "%s.%u", cpd.filename.c_str(), type);
snprintf(dumpFileName, sizeof(dumpFileName), "%s.%u", cpd.filename.c_str(), type);
}
else
{
sprintf(dumpFileName, "%s.%u", cpd.dumped_file, type);
snprintf(dumpFileName, sizeof(dumpFileName), "%s.%u", cpd.dumped_file, type);
}
FILE *D_file = fopen(dumpFileName, "w");

Expand Down Expand Up @@ -532,11 +532,11 @@ void dump_in(unsigned int type)

if (cpd.dumped_file == nullptr)
{
sprintf(dumpFileName, "%s.%u", cpd.filename.c_str(), type);
snprintf(dumpFileName, sizeof(dumpFileName), "%s.%u", cpd.filename.c_str(), type);
}
else
{
sprintf(dumpFileName, "%s.%u", cpd.dumped_file, type);
snprintf(dumpFileName, sizeof(dumpFileName), "%s.%u", cpd.dumped_file, type);
}
FILE *D_file = fopen(dumpFileName, "r");

Expand Down Expand Up @@ -722,7 +722,7 @@ char dump_file_name[80];

void set_dump_file_name(const char *name)
{
sprintf(dump_file_name, "%s", name);
snprintf(dump_file_name, sizeof(dump_file_name), "%s", name);
}


Expand Down

0 comments on commit a4cb495

Please sign in to comment.