File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 127
127
**************************************************************************/
128
128
129
129
#include "sdncal.h"
130
+ #include <limits.h>
130
131
131
132
#define GREGOR_SDN_OFFSET 32045
132
133
#define DAYS_PER_5_MONTHS 153
@@ -146,19 +147,14 @@ void SdnToGregorian(
146
147
long int temp ;
147
148
int dayOfYear ;
148
149
149
- if (sdn <= 0 ) {
150
- * pYear = 0 ;
151
- * pMonth = 0 ;
152
- * pDay = 0 ;
153
- return ;
150
+ if (sdn <= 0 ||
151
+ sdn > (LONG_MAX - 4 * GREGOR_SDN_OFFSET ) / 4 ) {
152
+ goto fail ;
154
153
}
155
154
temp = (sdn + GREGOR_SDN_OFFSET ) * 4 - 1 ;
156
155
157
156
if (temp < 0 ) {
158
- * pYear = 0 ;
159
- * pMonth = 0 ;
160
- * pDay = 0 ;
161
- return ;
157
+ goto fail ;
162
158
}
163
159
164
160
/* Calculate the century (year/100). */
@@ -190,6 +186,10 @@ void SdnToGregorian(
190
186
* pYear = year ;
191
187
* pMonth = month ;
192
188
* pDay = day ;
189
+ fail :
190
+ * pYear = 0 ;
191
+ * pMonth = 0 ;
192
+ * pDay = 0 ;
193
193
}
194
194
195
195
long int GregorianToSdn (
You can’t perform that action at this time.
0 commit comments