@@ -2883,6 +2883,9 @@ date_fromisoformat(PyObject *cls, PyObject *dtstr) {
2883
2883
Py_ssize_t len ;
2884
2884
2885
2885
const char * dt_ptr = PyUnicode_AsUTF8AndSize (dtstr , & len );
2886
+ if (dt_ptr == NULL ) {
2887
+ goto invalid_string_error ;
2888
+ }
2886
2889
2887
2890
int year = 0 , month = 0 , day = 0 ;
2888
2891
@@ -2894,12 +2897,15 @@ date_fromisoformat(PyObject *cls, PyObject *dtstr) {
2894
2897
}
2895
2898
2896
2899
if (rv < 0 ) {
2897
- PyErr_Format (PyExc_ValueError , "Invalid isoformat string: %s" ,
2898
- dt_ptr );
2899
- return NULL ;
2900
+ goto invalid_string_error ;
2900
2901
}
2901
2902
2902
2903
return new_date_subclass_ex (year , month , day , cls );
2904
+
2905
+ invalid_string_error :
2906
+ PyErr_Format (PyExc_ValueError , "Invalid isoformat string: %R" ,
2907
+ dtstr );
2908
+ return NULL ;
2903
2909
}
2904
2910
2905
2911
@@ -4258,15 +4264,18 @@ time_fromisoformat(PyObject *cls, PyObject *tstr) {
4258
4264
Py_ssize_t len ;
4259
4265
const char * p = PyUnicode_AsUTF8AndSize (tstr , & len );
4260
4266
4267
+ if (p == NULL ) {
4268
+ goto invalid_string_error ;
4269
+ }
4270
+
4261
4271
int hour = 0 , minute = 0 , second = 0 , microsecond = 0 ;
4262
4272
int tzoffset , tzimicrosecond = 0 ;
4263
4273
int rv = parse_isoformat_time (p , len ,
4264
4274
& hour , & minute , & second , & microsecond ,
4265
4275
& tzoffset , & tzimicrosecond );
4266
4276
4267
4277
if (rv < 0 ) {
4268
- PyErr_Format (PyExc_ValueError , "Invalid isoformat string: %s" , p );
4269
- return NULL ;
4278
+ goto invalid_string_error ;
4270
4279
}
4271
4280
4272
4281
PyObject * tzinfo = tzinfo_from_isoformat_results (rv , tzoffset ,
@@ -4286,6 +4295,10 @@ time_fromisoformat(PyObject *cls, PyObject *tstr) {
4286
4295
4287
4296
Py_DECREF (tzinfo );
4288
4297
return t ;
4298
+
4299
+ invalid_string_error :
4300
+ PyErr_Format (PyExc_ValueError , "Invalid isoformat string: %R" , tstr );
4301
+ return NULL ;
4289
4302
}
4290
4303
4291
4304
0 commit comments