Skip to content

Commit b264d8a

Browse files
committed
explicit checks of return value in format
1 parent d85db8e commit b264d8a

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

inst/NEWS.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
\newcommand{\ghit}{\href{https://github.com/RcppCore/Rcpp/issues/#1}{##1}}
55

66
\section{Changes in Rcpp version 0.12.9 (2017-01-xx)}{
7+
\itemize{
78
\item Changes in Rcpp API:
89
\itemize{
910
\item The exception stack message is now correctly demangled on all
@@ -19,8 +20,9 @@
1920
\item Changes in Rcpp Documentation:
2021
\itemize{
2122
\item Exposed pointers macros were included in the Rcpp Extending vignette
22-
(MathurinD; James Balamuta in \ghpr{592} addressing \ghit{418}).
23+
(MathurinD; James Balamuta in \ghpr{592} addressing \ghit{418}).
2324
}
25+
}
2426
}
2527

2628
\section{Changes in Rcpp version 0.12.8 (2016-11-16)}{

inst/include/Rcpp/date_datetime/Date.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,12 @@ namespace Rcpp {
106106
char txt[32];
107107
struct tm temp = m_tm;
108108
temp.tm_year -= baseYear(); // adjust for fact that system has year rel. to 1900
109-
::strftime(txt, 31, fmt, &temp);
110-
return std::string(txt);
109+
int res = ::strftime(txt, 31, fmt, &temp);
110+
if (res == 0) {
111+
return std::string("");
112+
} else {
113+
return std::string(txt);
114+
}
111115
}
112116

113117
friend inline std::ostream &operator<<(std::ostream & os, const Date d);

inst/include/Rcpp/date_datetime/Datetime.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,17 @@ namespace Rcpp {
7272
char txtiso[64], txtsec[64];
7373
time_t t = static_cast<time_t>(std::floor(m_dt));
7474
struct tm temp = *localtime(&t); // localtime, not gmtime
75-
::strftime(txtiso, 63, fmt, &temp);
76-
::snprintf(txtsec, 63, "%s.%06d", txtiso, m_us);
77-
return std::string(txtsec);
75+
int res = ::strftime(txtiso, 63, fmt, &temp);
76+
if (res == 0) {
77+
return std::string("");
78+
} else {
79+
res = ::snprintf(txtsec, 63, "%s.%06d", txtiso, m_us);
80+
if (res <= 0) {
81+
return std::string("");
82+
} else {
83+
return std::string(txtsec);
84+
}
85+
}
7886
}
7987

8088
friend inline std::ostream &operator<<(std::ostream & s, const Datetime d);

0 commit comments

Comments
 (0)