mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-18 15:55:12 +08:00
Merge pull request #2743 from seanm/snprintf2
Removed a use of sprintf that required changing a function signature
This commit is contained in:
commit
b99a263de6
@ -150,14 +150,14 @@ typedef struct timeinfo_t {
|
||||
# define MSC_NCTIME_EXTRA __declspec(dllimport)
|
||||
# endif
|
||||
|
||||
MSC_NCTIME_EXTRA extern void cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime);
|
||||
MSC_NCTIME_EXTRA extern void cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime, size_t chartime_size);
|
||||
MSC_NCTIME_EXTRA extern void cdChar2Comp(cdCalenType timetype, char* chartime, cdCompTime* comptime);
|
||||
MSC_NCTIME_EXTRA extern void Cdh2e(CdTime *htime, double *etime);
|
||||
MSC_NCTIME_EXTRA extern void Cde2h(double etime, CdTimeType timeType, long baseYear, CdTime *htime);
|
||||
MSC_NCTIME_EXTRA extern int cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTime* base_comptime);
|
||||
MSC_NCTIME_EXTRA extern int cdSetErrOpts(int opts);
|
||||
#else
|
||||
extern void cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime);
|
||||
extern void cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime, size_t chartime_size);
|
||||
extern void cdChar2Comp(cdCalenType timetype, char* chartime, cdCompTime* comptime);
|
||||
extern void Cdh2e(CdTime *htime, double *etime);
|
||||
extern void Cde2h(double etime, CdTimeType timeType, long baseYear, CdTime *htime);
|
||||
|
@ -1085,7 +1085,7 @@ cdRel2Comp(cdCalenType timetype, char* relunits, double reltime, cdCompTime* com
|
||||
|
||||
/* rkr: output as ISO 8601 strings */
|
||||
static void
|
||||
cdComp2Iso(cdCalenType timetype, int separator, cdCompTime comptime, char* time)
|
||||
cdComp2Iso(cdCalenType timetype, int separator, cdCompTime comptime, char* time, size_t time_size)
|
||||
{
|
||||
double dtmp, sec;
|
||||
int ihr, imin, isec;
|
||||
@ -1121,23 +1121,23 @@ cdComp2Iso(cdCalenType timetype, int separator, cdCompTime comptime, char* time)
|
||||
if(timetype & cdStandardCal){
|
||||
switch (nskip) {
|
||||
case 0: /* sec != 0 && (int)sec != sec */
|
||||
sprintf(time,"%4.4ld-%2.2hd-%2.2hd%c%2.2d:%2.2d:%lf",
|
||||
snprintf(time,time_size,"%4.4ld-%2.2hd-%2.2hd%c%2.2d:%2.2d:%lf",
|
||||
comptime.year,comptime.month,comptime.day,separator,ihr,imin,sec);
|
||||
break;
|
||||
case 1:
|
||||
sprintf(time,"%4.4ld-%2.2hd-%2.2hd%c%2.2d:%2.2d:%2.2d",
|
||||
snprintf(time,time_size,"%4.4ld-%2.2hd-%2.2hd%c%2.2d:%2.2d:%2.2d",
|
||||
comptime.year,comptime.month,comptime.day,separator,ihr,imin,isec);
|
||||
break;
|
||||
case 2:
|
||||
sprintf(time,"%4.4ld-%2.2hd-%2.2hd%c%2.2d:%2.2d",
|
||||
snprintf(time,time_size,"%4.4ld-%2.2hd-%2.2hd%c%2.2d:%2.2d",
|
||||
comptime.year,comptime.month,comptime.day,separator,ihr,imin);
|
||||
break;
|
||||
case 3:
|
||||
sprintf(time,"%4.4ld-%2.2hd-%2.2hd%c%2.2d",
|
||||
snprintf(time,time_size,"%4.4ld-%2.2hd-%2.2hd%c%2.2d",
|
||||
comptime.year,comptime.month,comptime.day,separator,ihr);
|
||||
break;
|
||||
case 4:
|
||||
sprintf(time,"%4.4ld-%2.2hd-%2.2hd",
|
||||
snprintf(time,time_size,"%4.4ld-%2.2hd-%2.2hd",
|
||||
comptime.year,comptime.month,comptime.day);
|
||||
break;
|
||||
}
|
||||
@ -1145,23 +1145,23 @@ cdComp2Iso(cdCalenType timetype, int separator, cdCompTime comptime, char* time)
|
||||
else { /* Climatological */
|
||||
switch (nskip) {
|
||||
case 0: /* sec != 0 && (int)sec != sec */
|
||||
sprintf(time,"%2.2hd-%2.2hd%c%2.2d:%2.2d:%lf",
|
||||
snprintf(time,time_size,"%2.2hd-%2.2hd%c%2.2d:%2.2d:%lf",
|
||||
comptime.month,comptime.day,separator,ihr,imin,sec);
|
||||
break;
|
||||
case 1:
|
||||
sprintf(time,"%2.2hd-%2.2hd%c%2.2d:%2.2d:%2.2d",
|
||||
snprintf(time,time_size,"%2.2hd-%2.2hd%c%2.2d:%2.2d:%2.2d",
|
||||
comptime.month,comptime.day,separator,ihr,imin,isec);
|
||||
break;
|
||||
case 2:
|
||||
sprintf(time,"%2.2hd-%2.2hd%c%2.2d:%2.2d",
|
||||
snprintf(time,time_size,"%2.2hd-%2.2hd%c%2.2d:%2.2d",
|
||||
comptime.month,comptime.day,separator,ihr,imin);
|
||||
break;
|
||||
case 3:
|
||||
sprintf(time,"%2.2hd-%2.2hd%c%2.2d",
|
||||
snprintf(time,time_size,"%2.2hd-%2.2hd%c%2.2d",
|
||||
comptime.month,comptime.day,separator,ihr);
|
||||
break;
|
||||
case 4:
|
||||
sprintf(time,"%2.2hd-%2.2hd",
|
||||
snprintf(time,time_size,"%2.2hd-%2.2hd",
|
||||
comptime.month,comptime.day);
|
||||
break;
|
||||
}
|
||||
@ -1171,12 +1171,12 @@ cdComp2Iso(cdCalenType timetype, int separator, cdCompTime comptime, char* time)
|
||||
|
||||
/* rkr: added for output closer to ISO 8601 */
|
||||
void
|
||||
cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime)
|
||||
cdRel2Iso(cdCalenType timetype, char* relunits, int separator, double reltime, char* chartime, size_t chartime_size)
|
||||
{
|
||||
cdCompTime comptime;
|
||||
|
||||
cdRel2Comp(timetype, relunits, reltime, &comptime);
|
||||
cdComp2Iso(timetype, separator, comptime, chartime);
|
||||
cdComp2Iso(timetype, separator, comptime, chartime, chartime_size);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1270,7 +1270,7 @@ nctime_val_tostring(const ncvar_t *varp, safebuf_t *sfbf, const void *valp) {
|
||||
oldopts = cdSetErrOpts(0);
|
||||
newopts = oldopts | CU_VERBOSE;
|
||||
cdSetErrOpts(newopts);
|
||||
cdRel2Iso(varp->timeinfo->calendar, varp->timeinfo->units, separator, vv, &sout[1]);
|
||||
cdRel2Iso(varp->timeinfo->calendar, varp->timeinfo->units, separator, vv, &sout[1], sizeof(sout) - 1);
|
||||
cdSetErrOpts(oldopts);
|
||||
res = strlen(sout);
|
||||
sout[res++] = '"';
|
||||
|
Loading…
Reference in New Issue
Block a user