Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sprintf -> snprintf #2691

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions h5_test/tst_h_compounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ main()
hr_data_out[i].starfleet_id = i;
hr_data_out[i].svc_rec.i1 = 95;
hr_data_out[i].svc_rec.i2 = 90;
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
if (snprintf(hr_data_out[i].name, sizeof(hr_data_out[i].name), "alien_%d", i) < 0) ERR;
seanm marked this conversation as resolved.
Show resolved Hide resolved
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .1;
Expand Down Expand Up @@ -557,7 +557,7 @@ main()
hr_data_out[i].starfleet_id = i;
hr_data_out[i].svc_rec.i1 = 95;
hr_data_out[i].svc_rec.i2 = 90;
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
if (snprintf(hr_data_out[i].name, sizeof(hr_data_out[i].name), "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .1;
Expand Down Expand Up @@ -665,7 +665,7 @@ main()
hr_data_out[i].starfleet_id = i;
hr_data_out[i].svc_rec.i1 = 95;
hr_data_out[i].svc_rec.i2 = 90;
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
if (snprintf(hr_data_out[i].name, sizeof(hr_data_out[i].name), "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99f;
hr_data_out[i].min_temp = -9.99f;
hr_data_out[i].percent_transporter_errosion = .1;
Expand Down Expand Up @@ -756,7 +756,7 @@ main()
/* Create some phony data. */
for (i = 0; i < DIM1_LEN; i++)
{
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
if (snprintf(hr_data_out[i].name, sizeof(hr_data_out[i].name), "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99f;
}

Expand Down Expand Up @@ -841,7 +841,7 @@ main()
/* Create some phony data. */
for (i = 0; i < DIM2_LEN; i++)
{
if (sprintf(hr_data_out[i].name, "alien_%d", i) < 0) ERR;
if (snprintf(hr_data_out[i].name, sizeof(hr_data_out[i].name), "alien_%d", i) < 0) ERR;
hr_data_out[i].max_temp = 99.99f;
}

Expand Down
2 changes: 1 addition & 1 deletion h5_test/tst_h_dimscales.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ main()
if ((var1_spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
for (v = 0; v < NUM_DATASETS; v++)
{
sprintf(var_name, "var_%d", v);
snprintf(var_name, sizeof(var_name), "var_%d", v);
if ((var1_datasetid[v] = H5Dcreate1(grpid, var_name, H5T_NATIVE_INT,
var1_spaceid, H5P_DEFAULT)) < 0) ERR;
if (H5DSattach_scale(var1_datasetid[v], dimscaleid, 0) < 0) ERR;
Expand Down
2 changes: 1 addition & 1 deletion h5_test/tst_h_dimscales4.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ main()
spaceid, create_propid)) < 0) ERR;
if (H5Sclose(spaceid) < 0) ERR;
if (H5Pclose(create_propid) < 0) ERR;
sprintf(dimscale_wo_var, "%s%10d", DIM_WITHOUT_VARIABLE, DIM_LEN);
snprintf(dimscale_wo_var, sizeof(dimscale_wo_var), "%s%10d", DIM_WITHOUT_VARIABLE, DIM_LEN);
if (H5DSset_scale(dimscaleid, dimscale_wo_var) < 0) ERR;

/* Create a variable that uses this dimension scale. */
Expand Down
6 changes: 3 additions & 3 deletions h5_test/tst_h_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ main()
void *bufr;
void *fillp = NULL;

sprintf(file_name, "%s/%s", TEMP_LARGE, FILE_NAME);
snprintf(file_name, sizeof(file_name), "%s/%s", TEMP_LARGE, FILE_NAME);

/* Create file access and create property lists. */
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
Expand Down Expand Up @@ -285,7 +285,7 @@ main()
spaceid, plistid)) < 0) ERR;
if (H5Sclose(spaceid) < 0) ERR;
if (H5Pclose(plistid) < 0) ERR;
sprintf(dimscale_wo_var, "%s%10d", DIM_WITHOUT_VARIABLE, DIM1);
snprintf(dimscale_wo_var, sizeof(dimscale_wo_var), "%s%10d", DIM_WITHOUT_VARIABLE, DIM1);
if (H5DSset_scale(dim1_dimscaleid, dimscale_wo_var) < 0) ERR;

/* Create the dim2 dimscale. */
Expand All @@ -299,7 +299,7 @@ main()
spaceid, plistid)) < 0) ERR;
if (H5Sclose(spaceid) < 0) ERR;
if (H5Pclose(plistid) < 0) ERR;
sprintf(dimscale_wo_var, "%s%10d", DIM_WITHOUT_VARIABLE, DIM2);
snprintf(dimscale_wo_var, sizeof(dimscale_wo_var), "%s%10d", DIM_WITHOUT_VARIABLE, DIM2);
if (H5DSset_scale(dim2_dimscaleid, dimscale_wo_var) < 0) ERR;

/* Now create the 2D dataset. */
Expand Down
2 changes: 1 addition & 1 deletion h5_test/tst_h_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ main()
/* Create the variables. */
for (v = 0; v < NUM_DATASETS; v++)
{
sprintf(var_name, "var_%d", v);
snprintf(var_name, sizeof(var_name), "var_%d", v);
/* printf("creating var %s\n", var_name);*/
if ((datasetid[v] = H5Dcreate1(grpid, var_name, H5T_NATIVE_INT,
spaceid, plistid)) < 0) ERR_RET;
Expand Down
2 changes: 1 addition & 1 deletion h5_test/tst_h_vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ main()
"szip_and_zlib"};

/* Open file and create group. */
sprintf(file_name, "%s_%s.h5", TEST_NAME, desc[f]);
snprintf(file_name, sizeof(file_name), "%s_%s.h5", TEST_NAME, desc[f]);
if ((fileid = H5Fcreate(file_name, H5F_ACC_TRUNC, H5P_DEFAULT,
H5P_DEFAULT)) < 0) ERR;
if ((grpid = H5Gcreate1(fileid, GRP_NAME, 0)) < 0) ERR;
Expand Down
2 changes: 1 addition & 1 deletion h5_test/tst_h_vars2.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ main()
/* Create the variables. */
for (v = 0; v < NUM_DATASETS; v++)
{
sprintf(var_name, "var_%d", v);
snprintf(var_name, sizeof(var_name), "var_%d", v);
/* printf("creating var %s\n", var_name);*/
if ((datasetid[v] = H5Dcreate1(grpid, var_name, H5T_NATIVE_INT,
spaceid, plistid)) < 0) ERR_RET;
Expand Down
2 changes: 1 addition & 1 deletion hdf4_test/tst_interops2.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ main(int argc, char **argv)
/* Create some HDF4 datasets. */
for (t = 0; t < NUM_TYPES; t++)
{
sprintf(tmp_name, "hdf4_dataset_type_%d", t);
snprintf(tmp_name, sizeof(tmp_name), "hdf4_dataset_type_%d", t);
if ((sds_id = SDcreate(sd_id, tmp_name, hdf4_type[t],
DIMS_3, dim_size)) == FAIL) ERR;
/* Set up dimensions. By giving them the same names for each
Expand Down
2 changes: 1 addition & 1 deletion libdap2/dapodom.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ dapodom_print(Dapodometer* odom)
if(odom->rank == 0) {
strlcat(line,"[]",sizeof(line));
} else for(i=0;i<odom->rank;i++) {
sprintf(tmp,"[%lu/%lu:%lu:%lu]",
snprintf(tmp,sizeof(tmp),"[%lu/%lu:%lu:%lu]",
seanm marked this conversation as resolved.
Show resolved Hide resolved
(size_t)odom->index[i],
(size_t)odom->start[i],
(size_t)odom->stride[i],
Expand Down
2 changes: 1 addition & 1 deletion libdap2/dcetab.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
return 1;
}

/* Avoid sprintf, as that infringes on the user's name space.
/* Avoid snprintf, as that infringes on the user's name space.
Don't have undefined behavior even if the translation
produced a string with the wrong number of "%s"s. */
{
Expand Down
2 changes: 1 addition & 1 deletion libdap4/d4odom.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ d4odom_print(D4odometer* odom)
if(odom->rank == 0) {
strlcat(line,"[]",sizeof(line));
} else for(i=0;i<odom->rank;i++) {
sprintf(tmp,"[%lu/%lu:%lu:%lu]",
snprintf(tmp,sizeof(tmp),"[%lu/%lu:%lu:%lu]",
(size_t)odom->index[i],
(size_t)odom->start[i],
(size_t)odom->stride[i],
Expand Down
2 changes: 1 addition & 1 deletion libdispatch/dparallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ parallel I/O.
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);

sprintf(file_name, "%s/%s", TEMP_LARGE, FILE);
snprintf(file_name, sizeof(file_name), "%s/%s", TEMP_LARGE, FILE);
if ((res = nc_create_par(file_name, NC_NETCDF4, comm, info, &ncid))) ERR;

if (nc_def_dim(ncid, "d1", DIMSIZE, dimids)) ERR;
Expand Down
2 changes: 1 addition & 1 deletion libdispatch/nctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTi
else{
cdTrim(basetime_1,CD_MAX_CHARTIME);
cdTrim(basetime_2,CD_MAX_CHARTIME);
sprintf(basetime,"%s %s",basetime_1,basetime_2);
snprintf(basetime,sizeof(basetime),"%s %s",basetime_1,basetime_2);
}
}

Expand Down
2 changes: 1 addition & 1 deletion libhdf5/hdf5open.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ create_phony_dims(NC_GRP_INFO_T *grp, hid_t hdf_datasetid, NC_VAR_INFO_T *var)
if (!match)
{
char phony_dim_name[NC_MAX_NAME + 1];
sprintf(phony_dim_name, "phony_dim_%d", grp->nc4_info->next_dimid);
snprintf(phony_dim_name, sizeof(phony_dim_name), "phony_dim_%d", grp->nc4_info->next_dimid);
LOG((3, "%s: creating phony dim for var %s", __func__, var->hdr.name));

/* Add phony dim to metadata list. */
Expand Down
7 changes: 4 additions & 3 deletions libhdf5/hdf5var.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ give_var_secret_name(NC_VAR_INFO_T *var, const char *name)
* clash. */
if (strlen(name) + strlen(NON_COORD_PREPEND) > NC_MAX_NAME)
return NC_EMAXNAME;
if (!(var->alt_name = malloc((strlen(NON_COORD_PREPEND) +
strlen(name) + 1) * sizeof(char))))
size_t alt_name_size = (strlen(NON_COORD_PREPEND) + strlen(name) + 1) *
sizeof(char);
if (!(var->alt_name = malloc(alt_name_size)))
return NC_ENOMEM;

sprintf(var->alt_name, "%s%s", NON_COORD_PREPEND, name);
snprintf(var->alt_name, alt_name_size, "%s%s", NON_COORD_PREPEND, name);

return NC_NOERR;
}
Expand Down
10 changes: 5 additions & 5 deletions libhdf5/nc4hdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,13 @@ write_quantize_att(NC_VAR_INFO_T *var)
switch (var->quantize_mode)
{
case NC_QUANTIZE_BITGROOM:
sprintf(att_name, "%s", NC_QUANTIZE_BITGROOM_ATT_NAME);
snprintf(att_name, sizeof(att_name), "%s", NC_QUANTIZE_BITGROOM_ATT_NAME);
seanm marked this conversation as resolved.
Show resolved Hide resolved
break;
case NC_QUANTIZE_GRANULARBR:
sprintf(att_name, "%s", NC_QUANTIZE_GRANULARBR_ATT_NAME);
snprintf(att_name, sizeof(att_name), "%s", NC_QUANTIZE_GRANULARBR_ATT_NAME);
break;
case NC_QUANTIZE_BITROUND:
sprintf(att_name, "%s", NC_QUANTIZE_BITROUND_ATT_NAME);
snprintf(att_name, sizeof(att_name), "%s", NC_QUANTIZE_BITROUND_ATT_NAME);
break;
default:
return NC_EINVAL;
Expand Down Expand Up @@ -1826,7 +1826,7 @@ nc4_create_dim_wo_var(NC_DIM_INFO_T *dim)
/* Indicate that this is a scale. Also indicate that not
* be shown to the user as a variable. It is hidden. It is
* a DIM WITHOUT A VARIABLE! */
sprintf(dimscale_wo_var, "%s%10d", DIM_WITHOUT_VARIABLE, (int)dim->len);
snprintf(dimscale_wo_var, sizeof(dimscale_wo_var), "%s%10d", DIM_WITHOUT_VARIABLE, (int)dim->len);
if (H5DSset_scale(hdf5_dim->hdf_dimscaleid, dimscale_wo_var) < 0)
BAIL(NC_EHDFERR);

Expand Down Expand Up @@ -2257,7 +2257,7 @@ nc4_rec_match_dimscales(NC_GRP_INFO_T *grp)
if (match < 0)
{
char phony_dim_name[NC_MAX_NAME + 1];
sprintf(phony_dim_name, "phony_dim_%d", grp->nc4_info->next_dimid);
snprintf(phony_dim_name, sizeof(phony_dim_name), "phony_dim_%d", grp->nc4_info->next_dimid);
LOG((3, "%s: creating phony dim for var %s", __func__, var->hdr.name));
if ((retval = nc4_dim_list_add(grp, phony_dim_name, h5dimlen[d], -1, &dim)))
{
Expand Down
7 changes: 4 additions & 3 deletions libnczarr/zvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,12 @@ give_var_secret_name(NC_VAR_INFO_T *var, const char *name)
* clash. */
if (strlen(name) + strlen(NON_COORD_PREPEND) > NC_MAX_NAME)
return NC_EMAXNAME;
if (!(var->ncz_name = malloc((strlen(NON_COORD_PREPEND) +
strlen(name) + 1) * sizeof(char))))
size_t ncz_name_size = (strlen(NON_COORD_PREPEND) + strlen(name) + 1) *
sizeof(char);
if (!(var->ncz_name = malloc(ncz_name_size)))
return NC_ENOMEM;

sprintf(var->ncz_name, "%s%s", NON_COORD_PREPEND, name);
snprintf(var->ncz_name, ncz_name_size, "%s%s", NON_COORD_PREPEND, name);

return NC_NOERR;
}
Expand Down
2 changes: 1 addition & 1 deletion libsrc/ffio.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ ncio_ffio_assign(const char *filename) {
errno=E2BIG;
return (const char *) NULL;
}
(void) sprintf(buffer,"-F %s %s", envstr,xtra_assign);
(void) snprintf(buffer,sizeof(buffer),"-F %s %s", envstr,xtra_assign);
#ifdef __crayx1
ASNFILE(filename, buffer, &istat, strlen(filename)+1, strlen(buffer)+1);
#else
Expand Down
20 changes: 10 additions & 10 deletions libsrc/pstdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,27 +763,27 @@ int main () {
uintmax_t umax = UINTMAX_C(0);
char str0[256], str1[256];

sprintf (str0, "%d %x\n", 0, ~0);
snprintf (str0, sizeof(str0), "%d %x\n", 0, ~0);

sprintf (str1, "%d %x\n", i8, ~0);
snprintf (str1, sizeof(str1), "%d %x\n", i8, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
sprintf (str1, "%u %x\n", u8, ~0);
snprintf (str1, sizeof(str1), "%u %x\n", u8, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
sprintf (str1, "%d %x\n", i16, ~0);
snprintf (str1, sizeof(str1), "%d %x\n", i16, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
sprintf (str1, "%u %x\n", u16, ~0);
snprintf (str1, sizeof(str1), "%u %x\n", u16, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
snprintf (str1, sizeof(str1), "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
snprintf (str1, sizeof(str1), "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
#ifdef INT64_MAX
sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
snprintf (str1, sizeof(str1), "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
#endif
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
snprintf (str1, sizeof(str1), "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
snprintf (str1, sizeof(str1), "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);

TESTUMAX(8);
Expand Down
4 changes: 2 additions & 2 deletions libsrc4/nc4internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ nc4_init_logging(void)
}

/* Create a filename with the rank in it. */
sprintf(log_filename, "nc4_log_%d.log", my_rank);
snprintf(log_filename, sizeof(log_filename), "nc4_log_%d.log", my_rank);

/* Open a file for this rank to log messages. */
if (!(LOG_FILE = fopen(log_filename, "w")))
Expand Down Expand Up @@ -1875,7 +1875,7 @@ rec_print_metadata(NC_GRP_INFO_T *grp, int tab_count)
strcpy(dims_string, "");
for (d = 0; d < var->ndims; d++)
{
sprintf(temp_string, " %d", var->dimids[d]);
snprintf(temp_string, sizeof(temp_string), " %d", var->dimids[d]);
strcat(dims_string, temp_string);
}
}
Expand Down
4 changes: 2 additions & 2 deletions nc_perf/bm_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,8 @@ main(int argc, char **argv)
#endif
/* Create a copy of file_out. This will defeat any buffering
* that may exist from the fact that we just wrote file_out. */
sprintf(file_out_2, "tst_copy_%s", file_out);
sprintf(cmd, "cp %s %s\n", file_out, file_out_2);
snprintf(file_out_2, sizeof(file_out_2), "tst_copy_%s", file_out);
snprintf(cmd, sizeof(cmd), "cp %s %s\n", file_out, file_out_2);
system(cmd);

if ((ret = cmp_file(file_in, file_out_2, &meta_read2_us, &data_read2_us,
Expand Down
4 changes: 2 additions & 2 deletions nc_perf/bm_many_atts.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ int main(int argc, char **argv)
ERR;

for(g = 1; g < numgrp + 1; g++) {
sprintf(gname, "group%d", g);
snprintf(gname, sizeof(gname), "group%d", g);
if (nc_def_grp(ncid, gname, &grp)) ERR;
natts = g < numgrp ? NC_MAX_ATTRS : aleft; /* leftovers on last time through */
for(an = 1; an < natts + 1; an++) {
char aname[20];
sprintf(aname, "attribute%d", a);
snprintf(aname, sizeof(aname), "attribute%d", a);
if (nc_put_att_int(grp, NC_GLOBAL, aname, NC_INT, 1, data)) ERR;
if(a%100 == 0) { /* only print every 100th attribute name */
if (gettimeofday(&end_time, NULL)) ERR;
Expand Down
6 changes: 3 additions & 3 deletions nc_perf/bm_many_objs.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char **argv)
/* create N groups, printing time after every 1000 */
numgrp = nitem;
for(g = 1; g < numgrp + 1; g++) {
sprintf(gname, "group%d", g);
snprintf(gname, sizeof(gname), "group%d", g);
if (nc_def_grp(ncid, gname, &grp)) ERR;
if (nc_def_var(grp, "var", NC_INT, 0, NULL, &var)) ERR;
if(nc_enddef (grp)) ERR;
Expand Down Expand Up @@ -80,13 +80,13 @@ int main(int argc, char **argv)
ERR;

for(g = 1; g < numgrp + 1; g++) {
sprintf(gname, "group%d", g);
snprintf(gname, sizeof(gname), "group%d", g);
if (nc_def_grp(ncid, gname, &grp)) ERR;
nvars = g < numgrp ? NC_MAX_VARS : vleft; /* leftovers on last time through */
for(vn = 1; vn < nvars + 1; vn++) {
int var;
char vname[20];
sprintf(vname, "variable%d", v);
snprintf(vname, sizeof(vname), "variable%d", v);
if(nc_def_var(grp, vname, NC_INT, 0, NULL, &var)) ERR;
if(nc_put_var(grp, var, data)) ERR;
if(v%1000 == 0) { /* only print every 1000th variable name */
Expand Down
8 changes: 4 additions & 4 deletions nc_perf/tst_attsperf.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ add_attributes(int ncid, int varid, size_t num_atts, size_t att_len)
/* Write a bunch of attributes. */
for (a = 0; a < num_atts; a++)
{
sprintf(att_name, "%s_varid_%d_att_%d", TEST, varid, a);
snprintf(att_name, sizeof(att_name), "%s_varid_%d_att_%d", TEST, varid, a);
if (nc_put_att_double(ncid, varid, att_name, NC_DOUBLE,
att_len, att_data)) ERR;
}
Expand All @@ -73,7 +73,7 @@ buildfile(size_t num_vars, size_t num_atts, size_t att_len, char *file_name)
for (v = 0; v < num_vars; v++)
{
char var_name[NC_MAX_NAME + 1];
sprintf(var_name, "%s_var_%d", TEST, v);
snprintf(var_name, sizeof(var_name), "%s_var_%d", TEST, v);
if (nc_def_var(ncid, var_name, NC_INT, NDIMS, dimids, &varid)) ERR;
if (add_attributes(ncid, v, num_atts, att_len)) ERR;
}
Expand Down Expand Up @@ -200,7 +200,7 @@ main(int argc, char **argv)
long long hdf5_open_time = 0;

/* Determine file name. */
sprintf(file_name, "%s_%d_%d.nc", TEST, num_vars, r);
snprintf(file_name, sizeof(file_name), "%s_%d_%d.nc", TEST, num_vars, r);

if (buildfile(num_vars, num_atts, ATT_LEN, file_name)) ERR;
if (readfile(file_name, &nc4_open_time, do_inq, num_vars)) ERR;
Expand Down Expand Up @@ -242,7 +242,7 @@ main(int argc, char **argv)
long long hdf5_open_time;

/* Determine file name. */
sprintf(file_name, "%s_%d_%d_%d.nc", TEST, num_vars, s, r);
snprintf(file_name, sizeof(file_name), "%s_%d_%d_%d.nc", TEST, num_vars, s, r);

if (buildfile(num_vars, num_atts, ATT_LEN, file_name)) ERR;
if (readfile(file_name, &nc4_open_time, do_inq, num_vars)) ERR;
Expand Down
Loading
Loading