Skip to content

Commit cffdc6c

Browse files
committed
EXODUS: sprintf -> snprintf conversion
1 parent a594a5c commit cffdc6c

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

packages/seacas/libraries/exodus/src/ex_field_utils.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const char *ex_component_field_name(ex_field *field, int component[EX_MAX_FIELD_
7676
}
7777

7878
// Build up name incrementally which makes it easier to handle an empty component_separator...
79-
sprintf(field_name, "%s", field->name);
79+
snprintf(field_name, EX_MAX_NAME + 1, "%s", field->name);
8080

8181
for (int i = 0; i < field->nesting; i++) {
8282
if (field->component_separator[i]) {
@@ -332,8 +332,8 @@ const char *ex_field_component_suffix(ex_field *field, int nest_level, int compo
332332
static char user_suffix[32];
333333
static char format[8];
334334
int width = number_width(field->cardinality[nest_level]);
335-
sprintf(format, "%c%d%dd", '%', 0, width);
336-
sprintf(user_suffix, format, component);
335+
snprintf(format, 8, "%c%d%dd", '%', 0, width);
336+
snprintf(user_suffix, 32, format, component);
337337
return user_suffix;
338338
}
339339

@@ -343,8 +343,8 @@ const char *ex_field_component_suffix(ex_field *field, int nest_level, int compo
343343
static char user_suffix[32];
344344
static char format[8];
345345
int width = number_width(field->cardinality[nest_level]);
346-
sprintf(format, "%c%d%dd", '%', 0, width);
347-
sprintf(user_suffix, format, component - 1);
346+
snprintf(format, 8, "%c%d%dd", '%', 0, width);
347+
snprintf(user_suffix, 32, format, component - 1);
348348
return user_suffix;
349349
}
350350

packages/seacas/libraries/exodus/src/ex_put_field_metadata.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int ex_put_field_metadata(int exoid, const ex_field field)
7979
int status = 0;
8080
static char *field_template = "Field@%s@%s";
8181
char attribute_name[NC_MAX_NAME + 1];
82-
sprintf(attribute_name, field_template, field.name, "type");
82+
snprintf(attribute_name, NC_MAX_NAME + 1, field_template, field.name, "type");
8383
if ((status = ex_put_integer_attribute(exoid, field.entity_type, field.entity_id, attribute_name,
8484
field.nesting, field.type)) != EX_NOERR) {
8585
exi_persist_leavedef(exoid, __func__);
@@ -89,7 +89,7 @@ int ex_put_field_metadata(int exoid, const ex_field field)
8989

9090
/* Do not write if empty... */
9191
if (field.type_name[0] != '\0') {
92-
sprintf(attribute_name, field_template, field.name, "type_name");
92+
snprintf(attribute_name, NC_MAX_NAME + 1, field_template, field.name, "type_name");
9393
if ((status = ex_put_text_attribute(exoid, field.entity_type, field.entity_id, attribute_name,
9494
field.type_name)) != EX_NOERR) {
9595
exi_persist_leavedef(exoid, __func__);
@@ -100,7 +100,7 @@ int ex_put_field_metadata(int exoid, const ex_field field)
100100

101101
/* Default component_separator is '_'. Avoid writing if that is what it is... */
102102
if (field.component_separator[0] != '_' || field.nesting > 1) {
103-
sprintf(attribute_name, field_template, field.name, "separator");
103+
snprintf(attribute_name, NC_MAX_NAME + 1, field_template, field.name, "separator");
104104
if ((status = ex_put_text_attribute(exoid, field.entity_type, field.entity_id, attribute_name,
105105
field.component_separator)) != EX_NOERR) {
106106
exi_persist_leavedef(exoid, __func__);
@@ -117,7 +117,7 @@ int ex_put_field_metadata(int exoid, const ex_field field)
117117
}
118118
}
119119
if (needs_cardinality) {
120-
sprintf(attribute_name, field_template, field.name, "cardinality");
120+
snprintf(attribute_name, NC_MAX_NAME + 1, field_template, field.name, "cardinality");
121121
if ((status = ex_put_integer_attribute(exoid, field.entity_type, field.entity_id,
122122
attribute_name, field.nesting, field.cardinality)) !=
123123
EX_NOERR) {
@@ -138,7 +138,7 @@ int exi_put_type_attribute(int exoid, const char *att_root, const char *name, co
138138
if (entry != NULL) {
139139
static char *template = "%s@%s@%s";
140140
char attribute_name[NC_MAX_NAME + 1];
141-
sprintf(attribute_name, template, att_root, name, type);
141+
snprintf(attribute_name, NC_MAX_NAME + 1, template, att_root, name, type);
142142
if (value_type == EX_INTEGER) {
143143
status = ex_put_integer_attribute(exoid, EX_GLOBAL, 0, attribute_name, cardinality, entry);
144144
}
@@ -329,7 +329,7 @@ int ex_put_field_suffices(int exoid, const ex_field field, const char *suffices)
329329
return EX_FATAL;
330330
}
331331

332-
sprintf(attribute_name, field_template, field.name, "suffices");
332+
snprintf(attribute_name, NC_MAX_NAME + 1, field_template, field.name, "suffices");
333333
if ((status = ex_put_text_attribute(exoid, field.entity_type, field.entity_id, attribute_name,
334334
suffices)) != EX_NOERR) {
335335
snprintf(errmsg, MAX_ERR_LENGTH,

packages/seacas/libraries/exodus/test/testwt-field-metadata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
8282
/* Write element block names */
8383
for (int i = 0; i < num_elem_blk; i++) {
8484
char block_names[32];
85-
sprintf(block_names, "block_%c", i + 'A');
85+
snprintf(block_names, 32, "block_%c", i + 'A');
8686
EXCHECK(ex_put_name(exoid, EX_ELEM_BLOCK, blocks[i].id, block_names));
8787
}
8888

0 commit comments

Comments
 (0)