Skip to content

Commit

Permalink
Ensure consistent buffer size for snprintf (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcleod authored Feb 6, 2024
1 parent 0176553 commit d2d8f61
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/simgear/props/props.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ SGPropertyNode::setIntValue (int value)
case props::STRING:
case props::UNSPECIFIED: {
char buf[128];
snprintf(buf, 128, "%d", value);
snprintf(buf, sizeof(buf), "%d", value);
result = set_string(buf);
break;
}
Expand Down Expand Up @@ -1621,7 +1621,7 @@ SGPropertyNode::setLongValue (long value)
case props::STRING:
case props::UNSPECIFIED: {
char buf[128];
snprintf(buf, 128, "%ld", value);
snprintf(buf, sizeof(buf), "%ld", value);
result = set_string(buf);
break;
}
Expand Down Expand Up @@ -1672,7 +1672,7 @@ SGPropertyNode::setFloatValue (float value)
case props::STRING:
case props::UNSPECIFIED: {
char buf[128];
snprintf(buf, 128, "%f", value);
snprintf(buf, sizeof(buf), "%f", value);
result = set_string(buf);
break;
}
Expand Down Expand Up @@ -1723,7 +1723,7 @@ SGPropertyNode::setDoubleValue (double value)
case props::STRING:
case props::UNSPECIFIED: {
char buf[128];
snprintf(buf, 128, "%f", value);
snprintf(buf, sizeof(buf), "%f", value);
result = set_string(buf);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/prep_plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int main(int argc, char **argv)
nokey = true;
while (1) {
new_filename=filename;
sprintf(num,"%d",file_ctr);
snprintf(num,sizeof(num),"%d",file_ctr);
new_filename.replace(new_filename.find("#"),1,num);
infile2.open(new_filename.c_str());
if (!infile2.is_open()) {
Expand Down
2 changes: 1 addition & 1 deletion utils/aeromatic++/Aircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Aircraft::get_verbose_description(int no_engines)
if (no_engines < 0) rv += ')';
}

snprintf(desc, 1024, "%s", rv.c_str());
snprintf(desc, sizeof(desc), "%s", rv.c_str());
return desc;
}

Expand Down

0 comments on commit d2d8f61

Please sign in to comment.